Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change woocommerce price style but only on single product page for the current product [duplicate]

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 !

like image 782
Matias Azar Avatar asked Oct 25 '25 14:10

Matias Azar


1 Answers

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
        }
    
    }
like image 70
Ozgur Sar Avatar answered Oct 27 '25 03:10

Ozgur Sar