-
-
Save ptrsmk/2b33abb574559ff4de70eb21d7e14e5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ps_filter_gateways($gateways) { | |
if ( is_checkout_pay_page() ) { | |
global $wp; | |
if ( isset( $wp->query_vars['order-pay'] ) ) { | |
$order_id = $wp->query_vars['order-pay']; | |
$order = wc_get_order($order_id); | |
if ($order) { | |
$order_items = $order->get_items('line_item'); | |
if ( ! empty( $order_items ) ) { | |
foreach ($order_items as $order_item) { | |
$productid = $order_item[ 'product_id' ]; | |
$vendor = get_post_field( 'post_author', $post_id ); | |
if ( ! empty($vendor) ) { | |
$ppaddress = get_user_meta( $vendor, 'pv_paypal', true ); | |
if (empty($ppaddress)) { | |
if (isset( $gateways['paypalap'] )) { | |
unset( $gateways['paypalap'] ); | |
break; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} else { | |
$cart_contents = WC()->cart->get_cart(); | |
if ( ! empty( $cart_contents ) ) { | |
foreach ( $cart_contents as $cart_item_key => $cart_item_data ) { | |
$product = $cart_item_data[ 'data' ]; | |
$productid = $product->id; | |
$vendor = get_post_field( 'post_author', $productid ); | |
if ( ! empty($vendor) ) { | |
$ppaddress = get_user_meta( $vendor, 'pv_paypal', true ); | |
if (empty($ppaddress)) { | |
if (isset( $gateways['paypalap'] )) { | |
unset( $gateways['paypalap'] ); | |
break; | |
} | |
} | |
} | |
} | |
} | |
} | |
return $gateways; | |
} | |
add_filter('woocommerce_available_payment_gateways','ps_filter_gateways'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment