Name Your Price: Hooks

This is a developer-level doc. It’s written for developers who are comfortable with PHP, JavaScript and WordPress hooks. If you aren’t, a Woo agency partner or developer can help. Custom code isn’t covered by our Support Policy, so we can’t write, debug or maintain customizations for you.

These are the PHP filters and actions Name Your Price provides, grouped by what you’re trying to do. Each group starts with an example, then lists its hooks. For where to put the code, see Developers.

Many hooks pass a $suffix. It tells price fields apart when there are several on one page, for example in a bundle. On a normal product page it’s empty.

Price field

↑ Back to top

Example: add a note under the price field

↑ Back to top
add_action( 'wc_nyp_after_price_input', function ( $product, $suffix ) {
	echo '<p class="nyp-note">' . esc_html__( 'Every amount helps.', 'your-textdomain' ) . '</p>';
}, 10, 2 );
  • wc_nyp_price_input_attributes
    Filter: $args, $product, $suffix
    Change how the field is built: input_type, classes, placeholder, input_label, and custom_attributes (for example step or pattern).
  • wc_nyp_price_input_label_text
    Filter: $text, $product
    Change the label with your own logic. $text includes the currency symbol.
  • wc_nyp_disable_quantity_selector
    Filter: $disable, $product
    Hide the quantity field based on your own logic.
  • wc_nyp_before, wc_nyp_after
    Action: $product, $suffix
    Add content outside the price field’s wrapper. New in 4.0.
  • wc_nyp_before_price_input, wc_nyp_after_price_input
    Action: $product, $suffix
    Add content inside the wrapper, before the label or after the field.
  • wc_nyp_before_price_label, wc_nyp_after_price_label
    Action: $product, $suffix
    Add content right before or after the label.

Prefer hooks to template overrides. If you do need one, copy single-product/price-input.php or single-product/minimum-price.php from the plugin’s templates folder to yourtheme/woocommerce/single-product/. Overrides need updating whenever the plugin’s template version changes.

Text and prices shown

↑ Back to top

These filters change the wording and prices Name Your Price shows, with logic the settings can’t express. The wording set on a product’s Name Your Price tab is applied through the same filters at priority 10. Use priority 20 or higher for your code to win, or lower than 10 to let the product’s own wording win.

Example: different suggested-price wording for one category

↑ Back to top
add_filter( 'wc_nyp_suggested_price_text', function ( $text, $product ) {
	$id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id();
	if ( has_term( 'donations', 'product_cat', $id ) ) {
		return __( 'Most donors give %PRICE%', 'your-textdomain' );
	}
	return $text;
}, 20, 2 );

Keep %PRICE% in the text. Name Your Price replaces it with the formatted price.

  • wc_nyp_suggested_price_text
    Filter: $text, $product
    Change the suggested price text before %PRICE% is replaced. New in 4.0.
  • wc_nyp_suggested_price_html
    Filter: $html, $product
    Change the finished suggested price HTML.
  • wc_nyp_minimum_price_text
    Filter: $text, $product
    Change the minimum price text before %PRICE% is replaced. New in 4.0.
  • wc_nyp_minimum_price_html
    Filter: $html, $product
    Change the finished minimum price HTML.
  • wc_nyp_is_minimum_hidden
    Filter: $hidden, $product_id, $product
    Hide or show the minimum based on your own logic.
  • wc_nyp_price_html
    Filter: $html, $product
    Change the price shown for a Name Your Price product in the shop and on the product page.
  • wc_nyp_variable_price_html
    Filter: $html, $product
    Change the “From:” price of a variable product with Name Your Price variations.
  • wc_nyp_is_variable_price_hidden
    Filter: $hidden, $product_id, $product
    Hide that “From:” price.
  • wc_nyp_add_to_cart_text
    Filter: $text, $product
    Change the shop button text.
  • wc_nyp_single_add_to_cart_text
    Filter: $text, $product
    Change the product page button text. An empty string uses WooCommerce’s own.
  • wc_nyp_replace_price_template
    Filter: $replace, $product
    Return false to stop Name Your Price moving the product price above the price field.

Prices and validation

↑ Back to top

The minimum and maximum prices returned by these filters are both shown and enforced. The product page and the cart check the price against the same values.

Example: cap the amount for guests

↑ Back to top
add_filter( 'wc_nyp_raw_maximum_price', function ( $maximum, $product_id, $product ) {
	if ( ! is_user_logged_in() ) {
		return 500;
	}
	return $maximum;
}, 20, 3 );
  • wc_nyp_raw_minimum_price
    Filter: $minimum, $product_id, $product
    Change the minimum price. Return false for no minimum.
  • wc_nyp_raw_maximum_price
    Filter: $maximum, $product_id, $product
    Change the maximum price. Return false for no maximum.
  • wc_nyp_raw_suggested_price
    Filter: $suggested, $product_id, $product
    Change the price in the suggested price text.
  • wc_nyp_raw_minimum_variation_price
    Filter: $minimum, $product_id, $product
    Change the lowest price used for a variable product’s “From:” price.
  • wc_nyp_get_initial_price
    Filter: $price, $product, $suffix
    Pre-fill the price field. An empty string leaves it empty.
  • wc_nyp_get_posted_price
    Filter: $price, $product, $suffix
    Change the price read from the submitted form, before it’s validated.
  • wc_nyp_sort_by_suggested_price
    Filter: $sort, $product
    Return true to sort products by suggested price instead of minimum. It applies when a product is saved, so re-save existing products.

Using a currency switcher? Name Your Price converts prices through these same filters. Test your code in each currency to check whether it receives, and should return, the store currency or the customer’s currency.

Suggested price buttons

↑ Back to top

When a product has 2 or more suggested prices, customers see one button per amount plus a Custom button that opens the price field. New in 4.0.

Example: set the amounts in code

↑ Back to top
add_filter( 'wc_nyp_suggested_prices', function ( $amounts, $product ) {
	$id = $product->get_parent_id() ? $product->get_parent_id() : $product->get_id();
	if ( empty( $amounts ) && has_term( 'donations', 'product_cat', $id ) ) {
		return array(
			array( 'price' => 10, 'default' => false ),
			array( 'price' => 25, 'default' => true ),
			array( 'price' => 50, 'default' => false ),
		);
	}
	return $amounts;
}, 20, 2 );

The amount marked default is selected when the page loads. Amounts are still checked against the product’s minimum and maximum, so an amount outside them can’t be added to the cart.

  • wc_nyp_suggested_prices
    Filter: $amounts, $product
    Change the amounts. Each one is an array with price and default. Fewer than 2 amounts shows no buttons.
  • wc_nyp_suggested_prices_layout
    Filter: $layout, $product
    Return 'after' to show the buttons below the price field instead of above it.

To change the buttons’ markup, override single-product/suggested-prices.php in your theme. Its default copy is in the plugin’s src/SuggestedPrices/templates folder.

Cart and edit in cart

↑ Back to top

Example: no Edit amount link for one category

↑ Back to top
add_filter( 'wc_nyp_show_edit_link_in_cart', function ( $show, $cart_item, $cart_item_key ) {
	if ( has_term( 'tickets', 'product_cat', $cart_item['product_id'] ) ) {
		return false;
	}
	return $show;
}, 10, 3 );

This works in the classic cart, the Cart block and the Store API, because they all check the same filter.

  • wc_nyp_show_edit_link_in_cart
    Filter: $show, $cart_item, $cart_item_key
    Show or hide the Edit amount link for an item. New in 4.0.
  • wc_nyp_edit_in_cart_text
    Filter: $text, $cart_item
    Change the link text. A product’s own Edit amount wording is applied at priority 10. New in 4.0.
  • wc_nyp_edit_in_cart_aria_label
    Filter: $label, $text, $product_name
    Change the link’s accessible name. Keep the visible text in it, so people using voice control can say what they see. New in 4.0.
  • wc_nyp_edited_cart_item
    Filter: $cart_item, $nyp, $cart_item_key
    Update your own data on a cart item when the customer changes the amount, before the new price is applied. For extensions that store something based on the amount. New in 4.0.

Tax

↑ Back to top

When a store enters prices including tax, WooCommerce normally takes off the store’s own tax and adds the customer’s tax. For a typed-in amount, Name Your Price changes that: the customer pays exactly the amount they entered, whatever their tax rate. The tax is worked out from inside that amount. Stores that enter prices excluding tax aren’t affected.

To charge typed-in amounts the way WooCommerce charges any other price that includes tax:

add_filter( 'wc_nyp_price_includes_customer_tax', '__return_false' );
  • wc_nyp_price_includes_customer_tax
    Filter: $includes, $product
    Return false to let the customer’s tax change what they pay. New in 4.0.

Subscriptions

↑ Back to top

These apply when WooCommerce Subscriptions is active.

  • wc_nyp_subscriptions_terms_html
    Filter: $terms, $product
    Change the subscription terms shown with the price field.
  • wc_nyp_is_billing_period_variable
    Filter: $variable, $product_id
    Decide whether the customer chooses the billing period.
  • wc_nyp_suggested_billing_period, wc_nyp_minimum_billing_period
    Filter: $period, $product_id
    Change the default and minimum billing period. Both default to month.
  • wc_nyp_get_posted_period
    Filter: $period, $product, $suffix
    Change the billing period read from the submitted form.
  • wc_nyp_subscription_strings
    Filter: $strings, $number, $period
    Change the billing period names, such as “month”.
  • wc_nyp_supports_variable_billing_period
    Filter: $show
    Return true to show the “customer chooses the billing period” option on every subscription product, not only those already using it.
  • wc_nyp_variable_subscription_nyp_html
    Filter: $html, $product
    Change the price shown for a variable subscription with Name Your Price variations.

Product types

↑ Back to top

Name Your Price works with simple, variable and subscription products, and with bundles, composites, Mix and Match products and deposits. To add another product type, for example one from your own plugin:

add_filter( 'wc_nyp_simple_supported_types', function ( $types ) {
	$types[] = 'my_custom_type';
	return $types;
} );

The Name Your Price checkbox then appears on products of that type. The price field is added on WooCommerce’s woocommerce_before_add_to_cart_button action, so the type’s add-to-cart form needs to run that action.

  • wc_nyp_simple_supported_types
    Filter: $types
    Add product types that can be Name Your Price products.
  • wc_nyp_variable_supported_types
    Filter: $types
    Add variable product types whose variations can be Name Your Price.
  • wc_nyp_is_nyp
    Filter: $is_nyp, $product_id, $product
    Decide whether a product is a Name Your Price product.
  • wc_nyp_has_nyp_variations
    Filter: $has_nyp, $product
    Decide whether a variable product has Name Your Price variations.

Document Version: 1.0.0
Last Updated: November 9th, 2026
NYP Version Covered: 4.0.0

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.