Restrict the Make an Offer button to logged-in users #
To restrict the Make an offer button in Name Your Price: Make Your Own Offer for WooCommerce, go to WPFactory > Price Offers > General, set User visibility to Logged-in users only, and save. Guests then no longer see the button or the offer form. To limit the button to a specific role, use the alg_wc_po_show_offer_price_button filter.
Correction to an earlier version of this article: Name Your Price includes a built-in User visibility option. You do not need the PHP snippet or the [price_offering_product_button] shortcode that a previous version suggested; that shortcode does not exist.
Use the built-in User visibility option #
- Go to WPFactory > Price Offers (also reachable at WooCommerce > Settings > Price Offers).
- Open the General section.
- Set User visibility (
alg_wc_po_offer_price_button_user_visibility) to Logged-in users only. - Save changes.
Guests will no longer see the button or the offer form. Signed-in users see it as normal.
Restricting by specific role #
The built-in option distinguishes between all users and logged-in users. To limit the button to a specific role (for example wholesale customers only), use the alg_wc_po_show_offer_price_button filter in a small snippet:
add_filter( 'alg_wc_po_show_offer_price_button', function ( $show, $product_id ) {
if ( ! current_user_can( 'read' ) ) {
return $show;
}
$user = wp_get_current_user();
return in_array( 'wholesale_customer', (array) $user->roles, true ) ? $show : false;
}, 10, 2 );
Return false to hide the button. This filter is documented in the Developer hooks and filters reference.
Tip #
If you require login, add a short note near your products directing guests to create an account, so the missing button does not look like an error.
Need a hand? #
Our team answers every ticket on the Name Your Price support forum.
