Advertisement
Guest User

Untitled

a guest
May 25th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <?php
  2.  
  3. function deactivate_paypal_unless_subscription( $available_gateways ) {
  4.  
  5. global $wp;
  6.  
  7. if ( class_exists( 'WC_Subscriptions_Cart' ) ) {
  8.  
  9. // version 1.5 and 2.0 compatibility
  10. $cart_contains_renewal = function_exists( 'wcs_cart_contains_renewal' ) ? wcs_cart_contains_renewal() : WC_Subscriptions_Cart::cart_contains_subscription_renewal();
  11.  
  12. if ( is_checkout_pay_page() ) {
  13. $order_contains_renewal = function_exists( 'wcs_order_contains_subscription' ) ? wcs_order_contains_subscription( $wp->query_vars['order-pay'] ) : WC_Subscriptions_Order::order_contains_subscription( $wp->query_vars['order-pay'] );
  14. } else {
  15. $order_contains_renewal = false;
  16. }
  17.  
  18. if ( ! WC_Subscriptions_Cart::cart_contains_subscription() || ! $cart_contains_renewal || ! $order_contains_renewal || ! WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment ) {
  19. if ( isset( $available_gateways['paypal'] ) ) {
  20. unset( $available_gateways['paypal'] );
  21. }
  22. }
  23. } else {
  24. if ( isset( $available_gateways['paypal'] ) ) {
  25. unset( $available_gateways['paypal'] );
  26. }
  27. }
  28.  
  29. return $available_gateways;
  30. }
  31. add_filter( 'woocommerce_available_payment_gateways', 'deactivate_paypal_unless_subscription', 11 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement