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

 

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.

WooCommerce - the most customizable eCommerce platform for building your online business.

Back to the top