Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. add_filter('woocommerce_available_payment_gateways', 'show_bacs_if_coupon_is_used', 99, 1);
  2. function show_bacs_if_coupon_is_used( $available_gateways ) {
  3.  
  4. $current_user = wp_get_current_user();
  5.  
  6. if ( isset($available_gateways['bacs']) && (current_user_can('customer'))) {
  7. unset($available_gateways['bacs']);
  8. } else if ( isset($available_gateways['bacs']) && !is_user_logged_in()) {
  9. unset($available_gateways['bacs']);
  10. }
  11. return $available_gateways;
  12. }
  13.  
  14. add_filter('woocommerce_available_payment_gateways', 'show_bacs_for_specific_applied_coupon', 99, 1);
  15. function show_bacs_for_specific_applied_coupon( $available_gateways ) {
  16. $coupon_code = 'FOOD';
  17.  
  18. if ( isset($available_gateways['bacs']) && ! ( is_user_logged_in() &&
  19. in_array( strtolower($coupon_code), WC()->cart->get_applied_coupons() ) ) ) {
  20. unset($available_gateways['bacs']);
  21. }
  22. return $available_gateways;
  23. }
  24.  
  25. add_filter('woocommerce_available_payment_gateways','show_cheque_for_specific_applied_coupon', 99, 1);
  26. function show_cheque_for_specific_applied_coupon( $available_gateways ) {
  27. $coupon_code = 'GRP-';
  28. if (in_array(strtolower($coupon_code), WC()->cart->get_applied_coupons() )) {
  29. unset($available_gateways['paypal']);
  30. unset($available_gateways['satispay']);
  31. unset($available_gateways['stripe']);
  32. }
  33. return $available_gateways;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement