Sale Badge percentage not shown issue compatibility for TopDeal theme
Resolve the issue where sale badge percentages do not display correctly in the TopDeal theme.
add_action('plugins_loaded', function() {
if (!function_exists('sw_label_sales')) {
function sw_label_sales(){
global $product, $post;
$product_type = ( sw_woocommerce_version_check( '3.0' ) ) ? : $product->product_type;
if( $product_type != 'variable' ) {
$forginal_price = get_post_meta( $post->ID, '_regular_price', true );
$fsale_price = get_post_meta( $post->ID, '_sale_price', true );
// Woo Discount Rules: Set initial and discounted price
$discount = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', false, $product, 1, 0, 'all', true, false);
if ($discount !== false && is_array($discount) && isset($discount['initial_price']) && isset($discount['discounted_price'])) {
$forginal_price = $discount['initial_price'];
$fsale_price = $discount['discounted_price'];
}
if( $fsale_price > 0 && $product->is_on_sale() ){
$sale_off = 100 - ( ( $fsale_price/$forginal_price ) * 100 );
$html = '<div class="sale-off ' . esc_attr( ( sw_label_new() != '' ) ? 'has-newicon' : '' ) .'">';
$html .= '<span>-' . round( $sale_off ).'%</span>';
$html .= '<span class="text">' . esc_html__( 'Off', 'topdeal' ) . '</span>';
$html .= '</div>';
echo apply_filters( 'sw_label_sales', $html );
}
}else{
echo '<div class="' . esc_attr( ( sw_label_new() != '' ) ? 'has-newicon' : '' ) .'">';
wc_get_template( 'single-product/sale-flash.php' );
echo '</div>';
}
}
}
});PreviousImproved compatibility for WooCommerce Wholesale Prices by Rymera Web CoNextMini cart is not update correctly when item added to or removed from cart
Last updated