Skip to content

Instantly share code, notes, and snippets.

@marcosnakamine
Last active March 10, 2017 13:20
Show Gist options
  • Save marcosnakamine/13b8b3ede57de49cec9530bcb5328e76 to your computer and use it in GitHub Desktop.
Save marcosnakamine/13b8b3ede57de49cec9530bcb5328e76 to your computer and use it in GitHub Desktop.
WooCommerce - Apply automatic discount coupon
<?php
add_action( 'woocommerce_before_cart', 'apply_auto_coupons' );
function apply_auto_coupons() {
if ( WC()->cart->get_cart_contents_count() >= 6 && !in_array( 'COUPON_CODE', WC()->cart->applied_coupons ) ) {
WC()->cart->add_discount( 'COUPON_CODE' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment