Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Created August 23, 2022 22:02
Show Gist options
  • Select an option

  • Save goranefbl/378671f7da489f80a9f54f2136cc6a1c to your computer and use it in GitHub Desktop.

Select an option

Save goranefbl/378671f7da489f80a9f54f2136cc6a1c to your computer and use it in GitHub Desktop.
Referral orders lower than 3
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