Skip to content

Instantly share code, notes, and snippets.

Last active September 3, 2016 02:52
What would you like to do?
Restrict payment gateways for Order Form for WooCommerce orders to the Cheque payment gateway. Available since version 1.8.0.
Plugin Name: Order Form for WooCommerce Cheque Only
Plugin URI:
Description: Only allow the Cheque payment gateway for order form purchases
Author: WebAware
Author URI:
if (!defined('ABSPATH')) {
* 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);
return $gateways;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment