Skip to content

Instantly share code, notes, and snippets.

@petenelson
Created May 20, 2026 20:14
Show Gist options
  • Select an option

  • Save petenelson/c29deb4cd54d75aef5e7aed67f2e0d9c to your computer and use it in GitHub Desktop.

Select an option

Save petenelson/c29deb4cd54d75aef5e7aed67f2e0d9c to your computer and use it in GitHub Desktop.
woocommerce-wp-cli.php
<?php
/**
* Plugin Name: WooCommerce WP-CLI Helpers
* Author: Pete Nelson
* Version: 1.0.0
* Requires at least: 6.7
*
* @package PeteNelson\WPCLIHelpers
*/
namespace PeteNelson\WPCLIHelpers;
use WP_CLI;
add_action( 'init', __NAMESPACE__ . '\setup' );
/**
* Setup the plugin.
*/
function setup() {
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_command( 'wc-helper deposits disable-payment-gateways', __NAMESPACE__ . '\disable_payment_gateways' );
}
}
/**
* Enable or disable payment gateways for deposits.
*
* ## OPTIONS
* <type>
* Use "all" to disable all gateways, "none" to enable all gateways,
* or any other string for a partial match to the gateway ID
* (e.g. "stripe" to disable "woocommerce_stripe"), or a comma-separated
* list of such strings to disable multiple gateways.
*
* ## EXAMPLES
*
* wp wc-helper deposits disable-payment-gateways all
* wp wc-helper deposits disable-payment-gateways none
* wp wc-helper deposits disable-payment-gateways paypal
* wp wc-helper deposits disable-payment-gateways square,braintree,stripe,ppcp
*
* @synopsis <type>
* @return void
*/
function disable_payment_gateways( array $args ) {
// Example: wp wc-helper deposits disable-payment-gateways square,braintree,stripe,ppcp
$type = $args[0];
// Disable all gateways for deposits by default, and then re-enable them if needed.
update_option( 'wc_deposits_disabled_gateways', [] );
if ( 'none' === $type ) {
WP_CLI::success( 'All payment gateways have been disabled for deposits.' );
return;
}
$payment_gateways = WC()->payment_gateways->payment_gateways();
$disabled_gateways = [];
$types = array_map( 'trim', explode( ',', $type ) );
foreach ( $payment_gateways as $gateway ) {
foreach ( $types as $t ) {
if ( 'all' === $t || str_contains( $gateway->id, $t ) ) {
$disabled_gateways[] = $gateway->id;
break;
}
}
}
update_option( 'wc_deposits_disabled_gateways', $disabled_gateways );
if ( 'all' === $type ) {
WP_CLI::success( 'All payment gateways have been enabled for deposits.' );
return;
} else {
WP_CLI::success( 'The following payment gateways have been disabled for deposits: ' . implode( ', ', $disabled_gateways ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment