Just like the title said:
How can i show only the sales price in Woocommerce if the regular price is blank?
2
I would go for something like:
$regular_price = get_post_meta( get_the_ID(), '_regular_price', true); $price_sale = get_post_meta( get_the_ID(), '_sale_price', true); if ($regular_price == '') { echo $price_sale; } else { echo $regular_price; }
add_filter( 'woocommerce_get_price_html', 'change_product_price_html', 10, 2 ); function change_product_price_html( $price_html, $product ) { global $post; $id = !empty( $product->get_id() ) ? $product->get_id() : $post->ID; $regular_price = get_post_meta( $id, '_regular_price', true); $sale_price = get_post_meta( $id, '_sale_price', true); $price_html = ( $regular_price == '' ) ? $sale_price : $regular_price; return $price_html; }
Please use this code in your active theme’s functions.php file .
Click here to cancel reply.
2
Answers
I would go for something like:
Please use this code in your active theme’s functions.php file .