I want to change the way prices are displayed on the product show page for all product that match the criteria. I have the following code:
function sv_change_product_price_display() {
global $product;
// $product = wc_get_product( $post->ID );
if ( $product->is_type( 'variable' ) ) {
if( has_term( 'joint', 'product_tag', $post->ID) ){
return $price;
}
if( has_term( 'Flowers', 'product_cat', $post->ID) ) {
$cost = $product->get_variation_price( 'max', true );
$cost = round($cost / 28, 2);
$cost = '<div class="amount"><b>Starting at $'.$cost.' per gram</b></div>';
$price = $cost;
return $price;
}
}
return $price;
}
add_filter( 'woocommerce_get_price_html', 'sv_change_product_price_display' );
This works on the show page but it also changes the prices on the single product page as well which is not what I want happening. I have tried different hooks to no avail either.
I want to change the way prices are displayed on the product show page for all product that match the criteria. I have the following code:
function sv_change_product_price_display() {
global $product;
// $product = wc_get_product( $post->ID );
if ( $product->is_type( 'variable' ) ) {
if( has_term( 'joint', 'product_tag', $post->ID) ){
return $price;
}
if( has_term( 'Flowers', 'product_cat', $post->ID) ) {
$cost = $product->get_variation_price( 'max', true );
$cost = round($cost / 28, 2);
$cost = '<div class="amount"><b>Starting at $'.$cost.' per gram</b></div>';
$price = $cost;
return $price;
}
}
return $price;
}
add_filter( 'woocommerce_get_price_html', 'sv_change_product_price_display' );
This works on the show page but it also changes the prices on the single product page as well which is not what I want happening. I have tried different hooks to no avail either.
Share Improve this question asked Dec 20, 2019 at 22:16 vredvred 11 Answer
Reset to default 0You can try with below condition for shop page only.
if ( $product->is_type( 'variable' ) && is_shop()) {