Skip to content

Instantly share code, notes, and snippets.

@danielbitzer
Last active September 14, 2022 11:12
Show Gist options
  • Save danielbitzer/3fbe558c3b67858e47a27c909706bae1 to your computer and use it in GitHub Desktop.
Save danielbitzer/3fbe558c3b67858e47a27c909706bae1 to your computer and use it in GitHub Desktop.
[Refer A Friend] Make referral coupons into free-gift coupons
<?php
add_filter( 'automatewoo/referrals/coupon_data', 'my_automatewoo_referrals_free_gift_coupon_data', 10, 4 );
/**
* Make AutomateWoo Refer A Friend coupons free gift coupons.
*
* REQUIRES: WooCommerce v3.6 and Refer A Friend v2.3.1
* REQUIRES: https://woocommerce.com/products/free-gift-coupons/
*
* @param array $coupon_data
* @param string $coupon_code
* @param int $advocate_id
* @param WC_Coupon $coupon
*
* @return array
*/
function my_automatewoo_referrals_free_gift_coupon_data( $coupon_data, $coupon_code, $advocate_id, $coupon ) {
$coupon_data['discount_type'] = 'free_gift';
// defines the product ID/s that will be free
$coupon->update_meta_data( 'gift_ids', [27,26] );
// defines whether shipping should be free
$coupon->update_meta_data( 'free_gift_shipping', false );
return $coupon_data;
}
@emranch31
Copy link

can you help me ?
i have set the prefix to empty string and coupons are not working on checkout.. which filter i can use t bypass the prefix check >?

@ManonSchipper
Copy link

Hello mr. Daniel,

I was looking for a fix to achieve just this and was happy to find your code. But when I implement it, it does not work.
How can I achieve this fix?

Thank you in advance

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