Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**Mycred restrict purchase if points are not enough**/
- add_filter( 'woocommerce_is_purchasable', 'mycred_deny_add_to_cart_if_insolvent', 10, 2 );
- function mycred_deny_add_to_cart_if_insolvent( $purchasable, $product ) {
- // Make sure myCRED is enabled and the product is purchasable
- if ( ! function_exists( 'mycred' ) || ! $purchasable ) return $purchasable;
- // Only applicable for product with the ID 123
- if ( $product->id != 123 ) return $purchasable;
- // Current Users ID
- $user_id = get_current_user_id();
- // Load myCRED
- $mycred = mycred();
- // Exempt Administrators from this rule
- if ( $mycred->can_edit_creds( $user_id ) ) return $purchasable;
- // Get price
- $price = $product->get_price();
- // Get users balance
- $balance = $mycred->get_users_balance( $user_id );
- // If balance is lower return false.
- if ( $balance < $price )
- return false;
- return $purchasable;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement