How can I add the sale badge back into my product carousel?

So i have some code which calculates the percentage discount and changes the “sale badge” to display the current discount percent.

However I just built some new loops using Elementor loop carousel and it no longer has the badge showing up? What code do I need to modify to make it include the badge on those aswell?

My loop carousel just has the property “featured image” and is a loop of products.

here is a pic of the discount badge, The badge itself is just included in my theme shoptimiser by default.

View post on imgur.com

and here is the loop carousel without the badge

View post on imgur.com

Just want to know where I need to look, Any googling just returns people using ACF to add the badge in themself, but I don’t believe I can use the same code I am using to change the text to be the discount percentage if I do that.

EDIT after some digging I found the code for getting the price of the product which I believe has a call to the function calling the display badge. I guess I just need to modify it to include loop products aswell?

function shoptimizer_change_displayed_sale_price_html() {

global $product, $price;
$shoptimizer_sale_badge = ”;

$shoptimizer_layout_woocommerce_display_badge = ”;
$shoptimizer_layout_woocommerce_display_badge = shoptimizer_get_option( ‘shoptimizer_layout_woocommerce_display_badge’ );

$shoptimizer_layout_woocommerce_display_badge_type = ”;
$shoptimizer_layout_woocommerce_display_badge_type = shoptimizer_get_option( ‘shoptimizer_layout_woocommerce_display_badge_type’ );

if ( $product->is_on_sale() && ! $product->is_type( ‘grouped’ ) && ! $product->is_type( ‘bundle’ ) ) {

if ( $product->is_type( ‘variable’ ) ) {
$percentages = array();

// Get all variation prices.
$prices = $product->get_variation_prices();

// Loop through variation prices.
foreach ( $prices[‘price’] as $key => $price ) {
// Only on sale variations.
if ( $prices[‘regular_price’][ $key ] !== $price && $prices[‘regular_price’][ $key ] > 0.005) {
// Calculate and set in the array the percentage for each variation on sale.
$percentages[] = round( 100 – ( $prices[‘sale_price’][ $key ] / $prices[‘regular_price’][ $key ] * 100 ) );
}
}
// Keep the highest value.
if ( ! empty( $percentages ) ) {
$percentage = max( $percentages ) . ‘%’;
}
} else {
$percentage = 0;
$regular_price = (float) $product->get_regular_price();
if ( $regular_price > 0.005 ) {
$sale_price = (float) $product->get_price();
$percentage = round( 100 – ( $sale_price / $regular_price * 100 ), 0 ) . ‘%’;
}
}

if ( isset( $percentage ) && $percentage > 0 ) {

if ( ‘bubble’ === $shoptimizer_layout_woocommerce_display_badge_type ) {
$shoptimizer_sale_badge .= sprintf( __( ‘<span class=”sale-item product-label type-bubble”>-%s</span>’, ‘shoptimizer’ ), $percentage );
}
else {
$shoptimizer_sale_badge .= sprintf( __( ‘<span class=”sale-item product-label type-circle”>-%s</span>’, ‘shoptimizer’ ), $percentage );
}
}
}

if ( true === $shoptimizer_layout_woocommerce_display_badge ) {
echo shoptimizer_safe_html( $shoptimizer_sale_badge );
}

}

 

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