'hide the price for protected products in shop page WooCommerce [closed]
Solution 1:[1]
To hide the price for protected products you can add a filter for displaying the price html and check if the product is protected, by checking to see if a password has been set, and if so return no value.
add_filter( 'woocommerce_get_price_html', 'hide_protected_product_price', 10, 2 );
function hide_protected_product_price( $price, $product ) {
if ( ! empty( $product->get_post_password() ) && ! is_single() ) {
return '';
}
return $price;
}
"Protected:" is added by WordPress not WooCommerce. To replace "Protected:" with "Reserved:" you need to add the protected_title_format filter. To make sure you only do it for products, first check the post_type
function jt_replace_product_protected_text( $prepend ) {
global $post;
if ( $post->post_type == 'product' ) {
return __( 'Reserved: %s' );
}
return $prepend;
}
add_filter( 'protected_title_format', 'jt_replace_product_protected_text' );
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
