Skip to content

Instantly share code, notes, and snippets.

@NickGreen
Last active March 9, 2020 18:17
Show Gist options
  • Save NickGreen/cc597ee2ec40bae64c1d9e0797a7f8fc to your computer and use it in GitHub Desktop.
Save NickGreen/cc597ee2ec40bae64c1d9e0797a7f8fc to your computer and use it in GitHub Desktop.
Getting subs for known product IDs
<?php
// for troubleshooting specific site.
add_action( 'wp', 'get_subs_by_products' );
function get_subs_by_products() {
$product_ids = array(39002, 39001, 27181, 26017, 73821, 4178);
$subscriptions = wcs_get_subscriptions( array( 'product_id' => $product_ids, 'subscriptions_per_page' => -1, 'subscription_status' => array( 'wc-active', 'wc-on-hold' ) ) );
$number_of_subs = count($subscriptions);
$log = new WC_Logger();
$log_entry = 'Subs count for existing products: ' . print_r( $number_of_subs, true );
$log->add( 'wcs-troubleshooting-log', $log_entry );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment