Advertisement
designbymerovingi

Limit myCRED Gateway in WooCommerce based on balance

Dec 4th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. /**
  2.  * Load Checkout Override
  3.  * @version 1.0
  4.  */
  5. add_action( 'after_setup_theme', 'mycred_pro_setup_woo_mycred_checkout', 120 );
  6. function mycred_pro_setup_woo_mycred_checkout() {
  7.  
  8.     if ( ! function_exists( 'mycred' ) || ! is_user_logged_in() ) return;
  9.  
  10.     remove_filter( 'woocommerce_available_payment_gateways', 'mycred_woo_available_gateways' );
  11.     add_filter( 'woocommerce_available_payment_gateways', 'mycred_pro_woo_checkout_limit' );
  12.  
  13. }
  14.  
  15. /**
  16.  * Limit Checkout Gateways
  17.  * Removes the myCRED gateway if a user has less then 5000 points
  18.  * @version 1.0
  19.  */
  20. function mycred_pro_woo_checkout_limit( $gateway ) {
  21.  
  22.     // prep
  23.     $user_id = get_current_user_id();
  24.     $mycred = mycred();
  25.  
  26.     // user is excluded
  27.     if ( $mycred->exclude_user( $user_id ) ) {
  28.         unset( $gateways['mycred'] );
  29.         return $gateways;
  30.     }
  31.  
  32.     // balance check
  33.     $balance = $mycred->get_users_balance( $user_id );
  34.     if ( $balance < 5000 ) {
  35.         unset( $gateways['mycred'] );
  36.         return $gateways;
  37.     }
  38.  
  39.     return $gateways;
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement