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.
Most of Name Your Price can be set up without code, on the Settings page and on each product’s Name Your Price tab (see Product settings). Use code only for what the settings can’t do, such as a minimum price that depends on who the customer is, or reacting to the price field in your own JavaScript.
The developer docs cover:
- Hooks: PHP filters and actions for the price field, prices and validation, the cart, tax and subscriptions.
- JavaScript events: what the price field reports while a customer types, and how to listen for it.
- Currency switchers: what a currency plugin needs to do so entered prices are converted once and charged correctly.
- REST API: Name Your Price fields on products and orders, for admin integrations.
- Store API: product data, adding to the cart with an amount, and changing it in the cart, for blocks and headless stores.
Adding custom code
↑ Back to topPut snippets in a code snippets plugin or in your child theme’s functions.php. Don’t edit Name Your Price’s own files, because updates overwrite them. Test on a staging site first.
Example: a lower minimum for logged-in customers
↑ Back to topEvery product’s minimum price passes through the wc_nyp_raw_minimum_price filter. The minimum shown on the product page and the minimum the cart accepts both come from it, so one filter changes both:
/**
* Lower the minimum price to 1.00 for logged-in customers.
*/
add_filter( 'wc_nyp_raw_minimum_price', function ( $minimum, $product_id, $product ) {
if ( is_user_logged_in() && is_numeric( $minimum ) ) {
return min( (float) $minimum, 1 );
}
return $minimum;
}, 10, 3 );
Products without a minimum are left alone. See Hooks: Prices and validation for the other price filters.
URL parameters
↑ Back to topLinks can pre-fill the price or add a product to the cart at a set price. This is useful for email campaigns, invoices and “Pay your bill” links.
| Parameter | What it does |
|---|---|
nyp | The price, as a plain number with a decimal point (for example 25 or 12.50). On a product page it fills in the price field, or selects the matching suggested-price button. With add-to-cart it sets the price of the item added. |
nyp-period | For subscriptions where the customer chooses the billing period: day, week, month or year. |
Pre-fill the product page, so the customer can still change the amount:
https://example.com/product/donation/?nyp=25
Add to the cart and go straight to checkout:
https://example.com/checkout/?add-to-cart=123&nyp=25
Replace 123 with the product’s ID. The price is checked the same way as on the product page, so an amount below the minimum or above the maximum isn’t added.
Document Version: 1.0.0
Last Updated: November 9th, 2026
NYP Version Covered: 4.0.0