Created
August 23, 2022 22:02
-
-
Save goranefbl/378671f7da489f80a9f54f2136cc6a1c to your computer and use it in GitHub Desktop.
Referral orders lower than 3
This file contains hidden or 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
| function custom_user_has_orders($user_email = false){ | |
| $user_id = get_current_user_id(); | |
| if($user_id == 0) { | |
| if($user_email !== false && $user_email != '') { | |
| $email_exists = get_posts( array( | |
| 'numberposts' => 1, | |
| 'meta_key' => '_billing_email', | |
| 'meta_value' => $user_email, | |
| 'post_type' => wc_get_order_types(), | |
| 'post_status' => array( 'wc-processing', 'wc-completed' ) | |
| ) ); | |
| return count($email_exists); | |
| } | |
| return 0; | |
| } | |
| $customer_orders = get_posts( array( | |
| 'numberposts' => 99999, | |
| 'meta_query' => array( | |
| array( | |
| 'key' => '_customer_user', | |
| 'value' => $user_id, | |
| ), | |
| ), | |
| 'post_type' => wc_get_order_types(), | |
| 'post_status' => 'wc-completed', | |
| ) ); | |
| return count($customer_orders); | |
| } | |
| function gens_limit_number_of_coupons($raf_info,$order,$referrer_id) { | |
| $has_orders = custom_user_has_orders(); | |
| if($has_orders < 3) { | |
| $raf_info = array("info" => "Referral is fine. Coupon will be generated on the order complete.", "generate" => "true", "increase_referrals" => "true", "email_notify" => "false"); | |
| } | |
| return $raf_info; | |
| } | |
| add_filter( 'gens_raf_order_info', 'gens_limit_number_of_coupons',10,3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment