Last active
August 25, 2021 17:00
-
-
Save artisanpixel/70eb6ad21d105a12741e98f5a4088cbf to your computer and use it in GitHub Desktop.
WooCommerce Local Pickup Plus - Conditional Payments based on Pickup Location
This file contains hidden or 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
<?php | |
/* | |
** Show and hide payment gateways based on local pickup plus locations | |
** Tested with Local Pickup Plus 2.3.11 and WooCommerce 3.3.5 | |
*/ | |
add_filter( 'woocommerce_available_payment_gateways', function ( $available_gateways ) { | |
// pass in the array of location ID's - same as the post ID of the locatoin visible in the URL | |
$limited_locations = array(101,102,579); // change these to your ID's | |
$packages = WC()->session->get('wc_local_pickup_plus_packages'); | |
// Remove PayPal from 'limited' locations | |
if ( isset( $packages["package_0"]) AND in_array( $packages["package_0"]["pickup_location_id"], $limited_locations )) { | |
unset($available_gateways["paypal"]); | |
} | |
// Remove cash only from all other locations | |
else { | |
unset($available_gateways["cod"]); | |
} | |
return $available_gateways; | |
}); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment