Answer the question
In order to leave comments, you need to log in
How to set a rule for this function?
Good afternoon dear colleagues. There was one problem that could not be solved. I wrote a code that if the price of the product is equal to zero or simply not recorded, then the phrase By request should be displayed. This idea turned out, but I can’t add a button to the product page. That is, the button should be only on those pages where there is a by request. The button should be below the Tags line. Under the price it turns out to be done, but not under Tags.
function product_price_free_zero_empty( $price, $product ){
if ( '' === $product->get_price() || 0 == $product->get_price() ) {
$price = '<span class="woocommerce-Price-amount amount">By request</span>';
}
return $price;
}
Answer the question
In order to leave comments, you need to log in
Your approach is fundamentally wrong. You are mixing logic and presentation, but that is a separate issue.
This:
if ( '' === $product->get_price() || 0 == $product->get_price() )
if (!$product->get_price())
product_price_free_zero_emptydisappears.
if (!$product->get_price()){
echo '<span class="woocommerce-Price-amount amount">By request</span>';
}
if (!$product->get_price()){
echo '<input type="button" value="Кнопка" /> ';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question