Skip to content

Instantly share code, notes, and snippets.

@hellerbenjamin
Last active October 7, 2023 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hellerbenjamin/b2f20963f93ac394a840c4aa2d57ba42 to your computer and use it in GitHub Desktop.
Save hellerbenjamin/b2f20963f93ac394a840c4aa2d57ba42 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