Advertisement
borkolivic

Disable COD 4 Local pickup method

Apr 30th, 2021
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. add_filter( 'woocommerce_available_payment_gateways', 'mx_disable_cod_for_local_pickup_method' );
  2.  
  3. function mx_disable_cod_for_local_pickup_method ( $available_gateways ) {
  4.  
  5.     global $woocommerce;
  6.  
  7.     if ( !is_admin() ) {
  8.  
  9.         $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
  10.  
  11.         $chosen_shipping = $chosen_methods[0];
  12.  
  13.         if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
  14.             unset( $available_gateways['cod'] );
  15.         }
  16.  
  17.     }
  18.  
  19. return $available_gateways;
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement