mrphpguru
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Woocommerce check if coupon is appliedadd_action( ‘woocommerce_before_cart’, ‘apply_matched_coupons’ );
function apply_matched_coupons() {
global $woocommerce;$get1 = ‘getonech’; // your coupon code here
$get2 = ‘gettwoch’; // your coupon code here
$get3 = ‘getthreech’; // your coupon code here
$get4 = ‘getfourch’; // your coupon code here
$get5 = ‘getfivech’; // your coupon code hereif ( $woocommerce->cart->cart_contents_count >= 1 && $woocommerce->cart->cart_contents_count < 2 ) {
$woocommerce->cart->add_discount( $get1 );
$woocommerce->show_messages();
} elseif ( $woocommerce->cart->cart_contents_count >= 2 && $woocommerce->cart->cart_contents_count < 3 ) {
$woocommerce->cart->add_discount( $get2 );
$woocommerce->show_messages();
} elseif ( $woocommerce->cart->cart_contents_count >= 3 && $woocommerce->cart->cart_contents_count < 4 ) {
$woocommerce->cart->add_discount( $get3 );
$woocommerce->show_messages();
} elseif ( $woocommerce->cart->cart_contents_count >= 4 && $woocommerce->cart->cart_contents_count < 5 ) {
$woocommerce->cart->add_discount( $get4 );
$woocommerce->show_messages();
} elseif ( $woocommerce->cart->cart_contents_count >= 5 ) {
$woocommerce->cart->add_discount( $get5 );
$woocommerce->show_messages();
}}
Forum: Fixing WordPress
In reply to: Woocommerce check if coupon is appliedStep 1: Create a coupon (https://docs.woothemes.com/document/coupon-management/)
Step 2: Add this code in your theme function.php
add_action( ‘woocommerce_before_cart’, ‘apply_matched_coupons’ );function apply_matched_coupons() {
global $woocommerce;$coupon_code = ’10percent’; // your coupon code here
if ( $woocommerce->cart->has_discount( $coupon_code ) ) return;
if ( $woocommerce->cart->cart_contents_total >= 500 ) {
$woocommerce->cart->add_discount( $coupon_code );
$woocommerce->show_messages();
}}