Forked from hellerbenjamin/gist:b2f20963f93ac394a840c4aa2d57ba42
Created
October 7, 2023 07:49
-
-
Save rafpro/702b8d6dcd23bdb5f58f5c8629a03794 to your computer and use it in GitHub Desktop.
Woocommerce Subscriptions WP CLI cheatsheet
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
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