Change displaying price for sold product

Hi there

I need to change price for sold product to “SOLD”

and I found this trick

add_filter('woocommerce_product_get_price','change_price_regular_member', woocommerce_currency_symbols, 10, 2 );

function change_price_regular_member( $price, $product)
{
        if (!$product->is_in_stock())
            $price = "SOLD";
        return $price;
}

but layout builder have 2 attributes {{dc:woocommerce:currency_symbol}}{{dc:woocommerce:product_price}}
so I get “$SOLD”

Could you tell me how I can hide currency symbol?

sorry I found a sollution. Can close )

// Change sold price
add_filter(‘woocommerce_product_get_price’,‘change_price_regular_member’, woocommerce_currency_symbols, 10, 2 );
function change_price_regular_member( $price, $product){
if (!$product->is_in_stock())
$price = “SOLD”;
return $price;
}

//hide currency for sold
add_filter(‘woocommerce_currency_symbol’, ‘change_existing_currency_symbol’, 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
$product = wc_get_product( get_the_ID() );

if ( is_a( $product, 'WC_Product' ) && $currency === 'USD' && ! $product->is_in_stock() ) {
    $currency_symbol = ''; 
}

return $currency_symbol; 

}

Hey There,

We are glad you’ve figured out a way to resolve your issue.

Thanks for letting us know!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.