Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Last active September 8, 2023 09:49
Show Gist options
  • Select an option

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

Select an option

Save goranefbl/ed063856fadf1c9c8bf94d4aab535b01 to your computer and use it in GitHub Desktop.
order tiers
<?php
add_filter('gens_raf_coupon_amount','change_coupon_amount',10, 2);
function change_coupon_amount($amount,$order_id){
// get number of referrals
$referrer_id = get_post_meta($order_id,'_wpgens_raf_id',true);
$user = reset(get_users(array('meta_key' => 'gens_referral_id', 'meta_value' => $referrer_id)));
$customer_orders = get_posts( array(
'numberposts' => - 1,
'meta_key' => '_customer_user',
'meta_value' => $user->ID,
'post_type' => array( 'shop_order' ),
'post_status' => array( 'wc-completed' )
) );
$total = 0;
foreach ( $customer_orders as $customer_order ) {
$order = wc_get_order( $customer_order );
$total += $order->get_total();
}
if($total > 500){
return $amount * 5;
} else if($total > 1000){
return $amount * 10;
}
return $amount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment