wordpress - How to add discount to cart total? -


i need add discount according number of product in cart , discount apply on total of cart. there other option without use of coupons?

this code should work:

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 3 items in cart, 10% discount has been added.';     } } 

the above apply coupon "maryscode" cart if there 4 or more products in customers cart.

edit: add following css

.coupon  {     display: none !important; } 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -