Skip to content

Instantly share code, notes, and snippets.

@braddalton
Last active November 10, 2023 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braddalton/63f8a13b48b3a81308191873bbd84e9b to your computer and use it in GitHub Desktop.
Save braddalton/63f8a13b48b3a81308191873bbd84e9b to your computer and use it in GitHub Desktop.
Coupon code in WooCommerce that provides a % discount and includes a free product https://wpsites.net/?p=114158
add_action('woocommerce_before_cart', 'apply_discount_and_add_free_product');
function apply_discount_and_add_free_product() {
global $woocommerce;
if (WC()->cart->has_discount('30OFF')) {
$free_product_id = 14646;
$quantity = 1;
WC()->cart->add_to_cart($free_product_id, $quantity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment