Untitled

 avatar
webwizards
plain_text
7 days ago
1.1 kB
5
Indexable
add_action( 'woocommerce_before_cart_table', 'custom_cart_discount_message' );
add_action( 'woocommerce_before_checkout_form', 'custom_cart_discount_message' );

function custom_cart_discount_message() {
    if ( ! function_exists( 'b2bking' ) || ! b2bking()->is_b2b_user() ) {
        return;
    }

    $threshold = 1000; // € HT
    $cart_total_ex_tax = WC()->cart->get_subtotal();

    if ( $cart_total_ex_tax >= $threshold ) {
        $message = '🎉 Félicitations ! Vous bénéficiez d\'une <strong>remise supplémentaire de 10&nbsp;%</strong> sur votre commande&nbsp;!';
        echo '<div class="woocommerce-info">' . $message . '</div>';
    } else {
        $remaining = $threshold - $cart_total_ex_tax;
        $remaining_formatted = number_format( $remaining, 2, ',', '&nbsp;' );
        $message = sprintf(
            '💡 <strong>-10&nbsp;%% supplémentaires</strong> dès 1&nbsp;000&nbsp;€ HT — plus que <strong>%s&nbsp;€</strong> pour en profiter&nbsp;!',
            $remaining_formatted
        );
        echo '<div class="woocommerce-info">' . $message . '</div>';
    }
}
Editor is loading...
Leave a Comment