joy
joy

Reputation: 101

Hide Price from WooCommerce Product Add-ons Dropdown if it's equal to zero

I found this post: Remove price from Woocommerce variable product dropdown menu, but it hides ALL variable prices. Instead I would like to hide the variable price if it is $0.00.

Can anyone help me with this?


Edit:

I didn't realize that the variation prices weren't part of WooCommerce. I am using WooCommerce Product Add-ons. I found this snippet that will target a specific product, but I don't know how to convert it to if !$0.00 condition. This post closer identifies my issue:
Hide displayed product prices from Woocommerce Product Add-ons Fields

Upvotes: 2

Views: 1368

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 254448

Based on Hide displayed product prices from Woocommerce Product Add-ons Fields answer code, you can try to use something like:

add_filter( 'woocommerce_product_addons_option_price', 'filter_product_addons_option_price', 10, 4 );
function filter_product_addons_option_price( $price_html, $option, $i, $type ){
    if( isset($option['price']) && ! ( $option['price'] > 0 ) ) {
        $price_html = '';
    }
    return $price_html;
}

Code goes in functions.php file of the active child theme (or active theme). It could works.

Upvotes: 1

Related Questions