Skip to content

Instantly share code, notes, and snippets.

@webaware
Last active September 3, 2016 02:52
Show Gist options
  • Save webaware/54b8e8a951224c3bef55464632dfd139 to your computer and use it in GitHub Desktop.
Save webaware/54b8e8a951224c3bef55464632dfd139 to your computer and use it in GitHub Desktop.
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/
<?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