Michelle
Michelle

Reputation: 549

How to modify wordpress/woocommerce php code to not apply to single product pages

I have the following code in my functions.php file -

add_filter( 'woocommerce_get_price_html', 'price_prefix_suffix', 100, 2 );
 
function price_prefix_suffix( $price, $product ){
    $price = '<span class="price-thin">From</span> ' . $price . '';
 return apply_filters( 'woocommerce_get_price', $price );  
}

I would like to change this code so it DOES NOT apply to single product pages. I only want this to apply to the home page, product category pages, but it is causing a problem when it appears on the single product page.

I am trying to add if(!is_product) to do this but I'm not sure where to put the if clause. Can anyone please help. Thanks

Upvotes: 0

Views: 48

Answers (1)

melvin
melvin

Reputation: 2621

You can use if clause inside the function,

add_filter( 'woocommerce_get_price_html', 'price_prefix_suffix', 100, 2 );
function price_prefix_suffix( $price, $product ){
    if( !is_product() ){
        $price = '<span class="price-thin">From</span> ' . $price . '';
    }
    return apply_filters( 'woocommerce_get_price', $price );  
}

Hope this works for you.

Upvotes: 1

Related Questions