K
K
Konstantin Timosheno2018-04-27 17:33:27
WordPress
Konstantin Timosheno, 2018-04-27 17:33:27

How to display label if price is 0 Woocommerce?

Hi all. There is such a need in the Woocommerce store, when the price is zero, that is, a free product, then display your inscription. I do this action

function filter_woocommerce_empty_price_html($price, $_product) {
  if ($_product->get_price() == 0) return __('<span class="woocommerce-Price-amount amount">Цену уточняйте</span>');
  return $price;
}
add_filter( 'woocommerce_empty_price_html', 'filter_woocommerce_empty_price_html', 10, 2 );

but it works when there is no price at all, and such a product cannot be put in the basket. Already broke my head in 2 days. Who can tell me what I'm doing wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Timosheno, 2018-04-27
@kastembay

Helped to decide

add_filter( 'woocommerce_get_price_html', 'product_price_free_zero_empty', 100, 2 );

function product_price_free_zero_empty( $price, $product ){
if ( '' === $product->get_price() || 0 == $product->get_price() ) {
    $price = '<span class="woocommerce-Price-amount amount">Цену уточняйте</span>';
}
return $price;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question