0

function custom_woocommerce_sale_text_shortcode($atts) {
    $atts = shortcode_atts(
        array('id' => ''), 
        $atts, 
        'sale_text'
    );
    if (empty($atts['id'])) {
        global $product;
    } else {
        $product = wc_get_product($atts['id']);
    }
    if (!$product) return '';
    if ($product->is_on_sale()) {
        return '<span class="sale_badge">Sale!</span>';
    }
    return '';
}
add_shortcode('sale_text', 'custom_woocommerce_sale_text_shortcode');

Jagdish Sarma Asked question 7 days ago
Add a Comment