Skip to content

Instantly share code, notes, and snippets.

@jessepearson
Created July 16, 2020 11:40
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 jessepearson/bc07df936e4c2e1516a44ffdda0d4bf7 to your computer and use it in GitHub Desktop.
Save jessepearson/bc07df936e4c2e1516a44ffdda0d4bf7 to your computer and use it in GitHub Desktop.
Allows for modifying the coupon that is created when AutomateWoo Refer A Friend is used.
<?php // do not copy this line
/**
* Allows for modifying the coupon that is created when AutomateWoo Refer A Friend is used.
*
* It works by modifying the coupon data that is used when creating the new coupon in the cart. The data that is
* able to be applied can be found here: https://github.com/woocommerce/woocommerce/blob/4.3.0/includes/class-wc-coupon.php#L26-L50
* Any edits will make the automatically generated coupon behave like a coupon created under WooCommerce > Coupons.
*
* This example make it so that if either categories 24 or 25 are in the cart, the referral is then applied.
*
*/
add_filter( 'automatewoo/referrals/store_credit/coupon_data', 'update_aw_referral_coupon_20200716' );
function update_aw_referral_coupon_20200716( $data ) {
// Uncomment anything you'd like to use.
// $data['product_ids'] = [];
// $data['excluded_product_ids'] = [];
// $data['limit_usage_to_x_items'] = null;
$data['product_categories'] = [ 24, 25 ];
// $data['excluded_product_categories'] = [];
// $data['exclude_sale_items'] = false;
// $data['maximum_amount'] = '';
return $data;
}
@mont58
Copy link

mont58 commented Apr 22, 2022

Hi, I tried to use this to exclude some product categories from the refer a friend coupon but it isn't working for me. this is the code i used and i assumed that the numbers are categories IDs? any advice? thank you

/**

  • Allows for modifying the coupon that is created when AutomateWoo Refer A Friend is used.
  • It works by modifying the coupon data that is used when creating the new coupon in the cart. The data that is
  • able to be applied can be found here: https://github.com/woocommerce/woocommerce/blob/4.3.0/includes/class-wc-coupon.php#L26-L50
  • Any edits will make the automatically generated coupon behave like a coupon created under WooCommerce > Coupons.
  • This example make it so that if either categories 24 or 25 are in the cart, the referral is then applied.

*/
add_filter( 'automatewoo/referrals/store_credit/coupon_data', 'update_aw_referral_coupon_20200716' );
function update_aw_referral_coupon_20200716( $data ) {
// Uncomment anything you'd like to use.
// $data['product_ids'] = [];
// $data['excluded_product_ids'] = [];
// $data['limit_usage_to_x_items'] = null;
// $data['product_categories'] = [];
$data['excluded_product_categories'] = [42, 34];
// $data['exclude_sale_items'] = false;
// $data['maximum_amount'] = '';
return $data;
}

@imranwaheed-10p
Copy link

Can i extend the plugin to not use any prefix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment