Hi I need to change the product price of the selected product on Woocommerce
i have this function
add_filter( 'woocommerce_get_price_html', 'custom_price_html', 11, 2 );
function custom_price_html($price_html, $product){
if (is_product()) {
// here I change the product price or styling
}
}
the problem is that function executes on the product page... but also on the related products on the bottom of the page.
how can I identify only the CURRENT PRODUCT PRICE ?!
Thanks !
You can add an extra check in your if statement to avoid changing price html for the related products loop.
add_filter( 'woocommerce_get_price_html', 'custom_price_html', 11, 2 );
function custom_price_html($price_html, $product){
global $woocommerce_loop;
if( is_product() && !$woocommerce_loop['name'] == 'related' ) {
// here I change the product price or styling
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With