Created
August 14, 2016 16:11
-
-
Save gedex/eb68baf0c5be490b6b2a5165dbbfecca to your computer and use it in GitHub Desktop.
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 | |
if ( ! defined( 'WP_CLI' ) ) { | |
return; | |
} | |
if ( ! WP_CLI ) { | |
return; | |
} | |
function _wc_clear_shipping_method_in_shipping_zones( $args ) { | |
if ( empty( $args[0] ) ) { | |
_wc_clear_shipping_method_usage(); | |
} | |
$shipping_method_id = 'usps'; | |
$zones = WC_Shipping_Zones::get_zones(); | |
$found = 0; | |
// First, check zone 0 (Rest of the world). | |
$rest_of_the_world = WC_Shipping_Zones::get_zone( 0 ); | |
foreach ( $rest_of_the_world->get_shipping_methods() as $shipping_method ) { | |
if ( $shipping_method_id === $shipping_method->id ) { | |
$found++; | |
} | |
} | |
// Zones added by user. | |
foreach ( $zones as $zone_id => $zone ) { | |
foreach ( $zone['shipping_methods'] as $shipping_method ) { | |
if ( 'usps' === $shipping_method->id ) { | |
$found++; | |
} | |
} | |
} | |
WP_CLI::success( sprintf( 'Cleared %d USPS method across shipping zones.', $found ) ); | |
} | |
function _wc_clear_shipping_method_usage() { | |
WP_CLI::line( 'Usage: wp clear_shipping_method <shipping_method_id>' ); | |
exit(1); | |
} | |
WP_CLI::add_command( 'clear_shipping_method', '_wc_clear_shipping_method_in_shipping_zones' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment