1. Documentation /
  2. Name Your Price /
  3. Name Your Price FAQ

Name Your Price FAQ

Answers to commonly asked questions about the WooCommerce Name Your Price extension.

Note: Customizations on this page are considered Developer level. If you are unfamiliar with code/templates and resolving potential conflicts, select a WooExpert or Developer for assistance. We are unable to provide support for customizations under our  Support Policy.

How do I change the markup?

↑ Back to top
Similar to WooCommerce, the Name Your Price extension uses a small template part to generate the markup for the minimum price and the price input. For example, you can use your own minimum price template by placing a minimum-product.php inside the /woocommerce/single-product folder of your theme. You can technically do the same with the price-input.php template, however, much of what makes the Name Your Price component function is wrapped up in helper functions in that template, so only edit this if you really know what you are doing.

How can I move the markup?

↑ Back to top
The suggested price in displayed in place of the regular price, which by default is attached to the WooCommerce woocommerce_single_product_summary action hook, while the text input is attached to the woocommerce_before_add_to_cart_button hook. The minimum price is attached to the woocommerce_nyp_after_price_input hook. Following typical WordPress behavior for hooks, to change the location of any of these templates you must remove them from their default hook and add them to a new hook. For example, to relocate the price input place the following in your theme’s functions.php and be sure to adjust the_hook_you_want_to_add_to with your desired hook’s name. To move the price input:
function nyp_move_price_input(){
  if( class_exists( 'WC_Name_Your_Price_Display' ) ) {
    remove_action( 'woocommerce_before_add_to_cart_button', array( WC_Name_Your_Price()->display, 'display_price_input' ), 9 );
    add_action( 'the_hook_you_want_to_add_to', array( WC_Name_Your_Price()->display, 'display_price_input' ) );
  }
}
add_action( 'woocommerce_before_single_product' , 'nyp_move_price_input' );
To not display a suggested price, you can simply leave the suggested field blank when setting up the product’s meta information. (See the Usage instructions). Similarly, to not enforce a minimum price, leave that field blank when setting up the product information.

How do I remove the stylesheet?

↑ Back to top
The Name Your Price stylesheet is pretty minimal, only offering a tiny bit of styling for the minimum price and for the text input. You can disable it from the plugin’s settings. Go to WooCommerce >Settings and click on the Name Your Price tab.

How can I hide the minimum price?

↑ Back to top
As mentioned above, the minimum price is attached to the WooCommerce woocommerce_single_product_summary action hook. Following typical WordPress behavior for hooks, to change the location of any of these templates you must remove them from their default hook. For example, to remove the minimum price (and to obfuscate the error messages), you’d place the following in your theme’s functions.php:
function nyp_remove_minimum_price(){
    remove_action( 'woocommerce_nyp_after_price_input', array( WC_Name_Your_Price()->display, 'display_minimum_price' ) );
}
add_action( 'woocommerce_nyp_before_price_input' , 'nyp_remove_minimum_price' );

function kia_change_minimum_error_templates( $templates ) {
       $templates['minimum'] = __( '"%%TITLE%%" could not be added to the cart: Please enter a higher price.', 'your-plugin-slug' );
       $templates['minimum_js'] = __( 'Please enter a higher price', 'your-plugin-slug' );
       return $templates;
}
add_action( 'woocommerce_nyp_error_message_templates', 'kia_change_minimum_error_templates' );

Force NYP products to be “sold individually”?

↑ Back to top
The same “name your price” product can still be added to cart if the price is different. This is because WooCommerce core generates a unique cart key from the cart item attributes, which includes the NYP price. Because “sold individually” can work a few different ways for people Name Your Price can’t force one system on all users. Therefore, if you wish to only sell 1 quantity of an item, then you can use the following code. It’s wrapped up as a plugin so you can simply upload it to wp-plugins and activate it. Requires WC 2.6.3  
<?php
/**
* Plugin Name: WooCommerce Name Your Price Sold Individually
* Plugin URI: https://gist.github.com/helgatheviking/a8802255167751a5dd746f83cdfc8716
* Description: Stricter enforcement of "Sold Individually" for NYP items
* Version: 1.2.0
* WC requires at least: 2.6.3
* Author: Kathy Darling
* Author URI: http://kathyisawesome.com/
*
* Copyright: © 2016 Kathy Darling
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
/**
* Attach hooks only when NYP is active.
*/
function wc_nyp_sold_individually_init() {
add_filter( 'woocommerce_cart_id', 'wc_nyp_force_sold_individually', 10, 5 );
}
add_action( 'wc_name_your_price_loaded', 'wc_nyp_sold_individually_init' );
/**
* Regenerate a unique ID for the cart item being added.
*
* @param string cart item key.
* @param int $product_id – id of the product the key is being generated for.
* @param int $variation_id of the product the key is being generated for.
* @param array $variation data for the cart item.
* @param array $cart_item_data other cart item data passed which affects this items uniqueness in the cart.
* @return string
*/
function wc_nyp_force_sold_individually( $cart_id, $product_id, $variation_id, $variation, $cart_item_data ) {
// Get the product.
$product = wc_get_product( $variation_id ? $variation_id : $product_id );
if ( $product->is_sold_individually() && WC_Name_Your_Price_Helpers::is_nyp( $product ) ){
$id_parts = array( $product_id );
if ( $variation_id && 0 != $variation_id ) {
$id_parts[] = $variation_id;
}
if ( is_array( $variation ) && ! empty( $variation ) ) {
$variation_key = '';
foreach ( $variation as $key => $value ) {
$variation_key .= trim( $key ) . trim( $value );
}
$id_parts[] = $variation_key;
}
$cart_id = md5( implode( '_', $id_parts ) );
}
return $cart_id;
}

Leave the price input blank

↑ Back to top
To always force the price input to be initially empty, regardless of suggested or minimum prices, then add the following line to your theme’s functions.php.
add_filter( 'woocommerce_nyp_get_initial_price', '__return_null' );

Add a placeholder to the price input

↑ Back to top
To add a placeholder attribute to the name your price <input> element you need to filter woocommerce_get_price_input by adding the following to your theme’s functions.php. https://gist.github.com/helgatheviking/e1326e2047ed621158f86c1d4747e9bc