Hello guys, I want to change the sale price position with the regular price on my single product page. This code I used works totally fine on the single product page, but it changes all the prices on the product archive page too.
I'm working with elementor pro and code snippets.
Is there a solution for that:
function custom_woocommerce_price_html($price, $product) {
if ( $product->is_on_sale() ) {
$sale_price = $product->get_sale_price();
$regular_price = $product->get_regular_price();
$price = '<span class="woocommerce-Price-amount amount sale sale-price-label-single">' . wc_price( $sale_price ) . '</span> <del class="regular-price-single">' . wc_price( $regular_price ) . '</del>';
} else {
$price = '<span class="woocommerce-Price-amount amount main-price-label-single">' . wc_price( $product->get_regular_price() ) . '</span>';
}
return $price;
}
add_filter('woocommerce_get_price_html', 'custom_woocommerce_price_html', 10, 2);

Try to workout via Woo hooks.