Restrict payment gateways for Order Form for WooCommerce orders to the Cheque payment gateway. Available since version 1.8.0. https://orderform-woo.webaware.net.au/
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
<?php | |
/* | |
Plugin Name: Order Form for WooCommerce Cheque Only | |
Plugin URI: https://gist.github.com/webaware/54b8e8a951224c3bef55464632dfd139 | |
Description: Only allow the Cheque payment gateway for order form purchases | |
Author: WebAware | |
Author URI: https://orderform-woo.webaware.net.au/ | |
*/ | |
if (!defined('ABSPATH')) { | |
exit; | |
} | |
/** | |
* restrict payment gateway for order form purchases | |
* @param array $gateways | |
* @return array | |
*/ | |
add_filter('woocommerce_available_payment_gateways', function($gateways) { | |
$cart = WC()->cart->get_cart(); | |
foreach ($cart as $cart_item) { | |
// was this item added from an order form? | |
if (!empty($cart_item['orderform_woocommerce']['flag'])) { | |
// get cheque payment gateway | |
if (!empty($gateways['cheque'])) { | |
$cheque_gateway = $gateways['cheque']; | |
} | |
else { | |
$cheque_gateway = new WC_Gateway_Cheque(); | |
} | |
// only allow cheque payment gateway | |
$gateways = array('cheque' => $cheque_gateway); | |
break; | |
} | |
} | |
return $gateways; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment