Last active
September 14, 2022 11:12
-
-
Save danielbitzer/3fbe558c3b67858e47a27c909706bae1 to your computer and use it in GitHub Desktop.
[Refer A Friend] Make referral coupons into free-gift coupons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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