How to add discount to cart total using woocommerce ?
add_action('woocommerce_before_cart_table', 'discount_when_produts_in_cart');
function discount_when_produts_in_cart( ) {
global $woocommerce;
if( $woocommerce->cart->cart_contents_count > 3 ) {
$coupon_code = 'maryscode';
if (!$woocommerce->cart->add_discount( sanitize_text_field( $coupon_code ))) {
$woocommerce->show_messages();
}
echo '<div class="woocommerce_message"><strong>You have more than 3 items in your cart, a 10% discount has been added.';
}
}
add_action('woocommerce_before_cart_table', 'discount_when_produts_in_cart');
function discount_when_produts_in_cart( ) {
global $woocommerce;
if( $woocommerce->cart->cart_contents_count > 3 ) {
$coupon_code = 'maryscode';
if (!$woocommerce->cart->add_discount( sanitize_text_field( $coupon_code ))) {
$woocommerce->show_messages();
}
echo '<div class="woocommerce_message"><strong>You have more than 3 items in your cart, a 10% discount has been added.';
}
}
No comments:
Post a Comment