Sale price Position

[ad_1]

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);

[ad_2]
1 Comment

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer