Skip to content

Instantly share code, notes, and snippets.

@jcasabona
Last active July 8, 2019 17:15
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 jcasabona/7f025ad8dcc14d84d56312f902a5aa12 to your computer and use it in GitHub Desktop.
Save jcasabona/7f025ad8dcc14d84d56312f902a5aa12 to your computer and use it in GitHub Desktop.
WooCommerce URL Coupons - Get Deferred Coupons
<?php
/** This function works with WooCommerce URL Coupons
* When a coupon gets deferred, it's added to a list of deferred_url_coupons.
* This function accepts a coupon ID ($coupon_id) as an argument, and gets all of the deferred_coupons
* as an array. The coupon ID would be an array key,which is what this function checks for.
* A message is printed. nothing is returned.
**/
function get_deferred_coupons( $coupon_id ) {
global $woocommerce;
$deferred_coupons = $woocommerce->session->get( 'deferred_url_coupons', array() );
if( array_key_exists( $coupon_id, $deferred_coupons ) ) {
echo '<p>Hey! Your coupon will be automattically applied at checkout!</p>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment