Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rafpro/702b8d6dcd23bdb5f58f5c8629a03794 to your computer and use it in GitHub Desktop.
Save rafpro/702b8d6dcd23bdb5f58f5c8629a03794 to your computer and use it in GitHub Desktop.
Woocommerce Subscriptions WP CLI cheatsheet
Woocommerce Subscription WP CLI Cheatsheet
Reviews
Enable Reviews on all
wp db query 'UPDATE wp_posts SET comment_status="open" WHERE post_type="product" AND comment_status="closed"'
Query disabled reviews
wp db query 'SELECT ID FROM wp_posts WHERE post_type="product" AND comment_status="closed" AND post_status="publish"'
Get subs for product
wcs_get_subscriptions_for_product( $product_id, $fields = 'id' )
Get subs for product and user cancel
$subscriptions = wcs_get_subscriptions_for_product( id ); foreach ( $subscriptions as $sub ) { echo $sub . "\n"; WCS_User_Change_Status_Handler::change_users_subscription( $sub, "cancelled" ); }
Get subs for product and admin cancel with note
$subscriptions = wcs_get_subscriptions_for_product( 793215 ); foreach ( $subscriptions as $sub ) { echo $sub . "\n"; $s = new WC_Subscription($sub ); $s->update_status( "cancelled", "This subscription is no longer offered"); }
Deactivate all Subscriptions
$subscriptions = get_posts( array( "post_status" => "wc-active" ) ); foreach ( $subscriptions as $sub ) { var_dump $sub; $s = new WC_Subscription($sub->ID ); $s->update_status( "cancelled", "off"); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment