Hi Waqar,
Thanks for the assistance!
I made the change suggested it's still not working so I turned on debug log and found some errors:
First, here is the new code:
// set Listing to draft if subscription expires
add_action( 'woocommerce_subscription_status_updated', 'status_update_callback', 1, 3);
function status_update_callback( $subscription, $old_status, $new_status ) {
$updated_sub_user_id = $subscription->get_user_id();
$args = array(
'author' => $updated_sub_user_id,
'post_type' => 'listing',
'orderby' => 'post_date',
'order' => 'ASC',
'posts_per_page' => 1
);
$member_profile_post = new WP_Query( $args );
$mp_post_id = $member_profile_post[0]->ID;
$mp_post_args = array( 'ID' => $mp_post_id, 'post_status' => 'draft' );
wp_update_post($mp_post_args);
}
Here are the errors. Note that the first error was a typo $member_profile_posts instead of $member_profile_posts.
Here's the output from the log:
[22-Dec-2021 23:48:22 UTC] PHP Notice: Undefined variable: member_profile_posts in /wp-content/themes/generatepress_ied/functions.php on line 52
[22-Dec-2021 23:48:22 UTC] PHP Notice: Trying to get property 'ID' of non-object in /wp-content/themes/generatepress_ied/functions.php on line 52
[23-Dec-2021 02:17:29 UTC] PHP Fatal error: Uncaught Error: Cannot use object of type WP_Query as array in /wp-content/themes/generatepress_ied/functions.php:52
Stack trace:
#0 /wp-includes/class-wp-hook.php(303): status_update_callback(Object(WC_Subscription), 'active', 'on-hold')
#1 /wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#2 /wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#3 /wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php(584): do_action('woocommerce_sub...', Object(WC_Subscription), 'active', 'on-hold')
#4 /wp-content/plugins/woocommerce/includes/class-wc-order.php(222): WC_Subscription->status_transition()
#5 /wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php(529): WC_Order->save()
#6 /home/j2a2w/ie in /wp-content/themes/generatepress_ied/functions.php on line 52
[23-Dec-2021 03:22:46 UTC] PHP Fatal error: Uncaught Error: Cannot use object of type WP_Query as array in /wp-content/themes/generatepress_ied/functions.php:52
Stack trace:
#0 /wp-includes/class-wp-hook.php(303): status_update_callback(Object(WC_Subscription), 'on-hold', 'active')
#1 /wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#2 /wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#3 /wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php(584): do_action('woocommerce_sub...', Object(WC_Subscription), 'on-hold', 'active')
#4 /wp-content/plugins/woocommerce/includes/class-wc-order.php(222): WC_Subscription->status_transition()
#5 /wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php(529): WC_Order->save()
#6 /home/j2a2w/ie in /wp-content/themes/generatepress_ied/functions.php on line 52
[23-Dec-2021 03:22:48 UTC] PHP Fatal error: Uncaught Error: Cannot use object of type WP_Query as array in /wp-content/themes/generatepress_ied/functions.php:52
Stack trace:
#0 /wp-includes/class-wp-hook.php(303): status_update_callback(Object(WC_Subscription), 'expired', 'on-hold')
#1 /wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#2 /wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#3 /wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php(584): do_action('woocommerce_sub...', Object(WC_Subscription), 'expired', 'on-hold')
#4 /wp-content/plugins/woocommerce/includes/class-wc-order.php(222): WC_Subscription->status_transition()
#5 /wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php(529): WC_Order->save()
#6 /home/j2a2w/ in /wp-content/themes/generatepress_ied/functions.php on line 52
Line 52 in functions.php = $mp_post_id = $member_profile_post[0]->ID;
Also seeing errors in WooCommerce logs:
12-22-2021 @ 22:22:46 - scheduled action 425 (subscription payment) failed to finish processing due to the following error: Uncaught Error: Cannot use object of type WP_Query as array in /wp-content/themes/generatepress_ied/functions.php:52
Stack trace:
#0 /wp-includes/class-wp-hook.php(303): status_update_callback(Object(WC_Subscription), 'on-hold', 'active')
#1 /wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#2 /wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#3 /wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php(584): do_action('woocommerce_sub...', Object(WC_Subscription), 'on-hold', 'active')
#4 /wp-content/plugins/woocommerce/includes/class-wc-order.php(222): WC_Subscription->status_transition()
#5 /wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php(529): WC_Order->save()
#6 /home/j2a2w/ie
12-22-2021 @ 22:22:46 - action args: subscription_id: 646
12-22-2021 @ 22:22:48 - scheduled action 426 (subscription expiration) failed to finish processing due to the following error: Uncaught Error: Cannot use object of type WP_Query as array in /wp-content/themes/generatepress_ied/functions.php:52
Stack trace:
#0 /wp-includes/class-wp-hook.php(303): status_update_callback(Object(WC_Subscription), 'expired', 'on-hold')
#1 /wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#2 /wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#3 /wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php(584): do_action('woocommerce_sub...', Object(WC_Subscription), 'expired', 'on-hold')
#4 /wp-content/plugins/woocommerce/includes/class-wc-order.php(222): WC_Subscription->status_transition()
#5 /wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscription.php(529): WC_Order->save()
#6 /home/j2a2w/
12-22-2021 @ 22:22:48 - action args: subscription_id: 646
and this in admin panel:
An error has occurred while processing recent subscription related events. For steps on how to fix the affected subscriptions and to learn more about the possible causes of this error, please read our guide here.
Affected events:
subscription payment for #646
subscription expiration for #646
To see further details about these errors, view the failed-scheduled-actions log file from the WooCommerce logs screen.
THANK YOU!