WooCommerce Argument 1 missing for WC_Subscriptions_Manager :: prepare_renewal ()

I get this in error logs whenever cron starts automatic subscription renewal for my client.

[Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: Stack trace:, referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000 [Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: #0 [internal function]: WC_Subscriptions_Payment_Gateways::gateway_scheduled_subscription_payment(), referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000 [Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: #1 /var/home/hybrid/completehumanperformance.com/www/wp-includes/class-wp-hook.php(298): call_user_func_array('WC_Subscription...', Array), referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000 [Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: #2 /var/home/hybrid/completehumanperformance.com/www/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array), referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000 [Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: #3 /var/home/hybrid/completehumanperformance.com/www/wp-includes/plugin.php(515): WP_Hook->do_action(Array), referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000 [Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: #4 /var/home/hybrid/completehumanperformance.com/www/wp-cron.php(117): do_action_ref_array('woocommerce_sch...', Array), referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000 [Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: #5 {main}, referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000 [Wed Nov 22 06:45:01 2017] [error] [client 204.187.12.186] FastCGI: server "/php-completehumanperformancecom.fpm" stderr: thrown in /var/home/hybrid/completehumanperformance.com/www/wp-content/plugins/woocommerce-subscrip..., referer: http://completehumanperformance.com/wp-cron.php?doing_wp_cron=1511361900.1951580047607421875000 

summary: Missing argument 1 for WC_Subscriptions_Manager::prepare_renewal()

I created cron using the WP_Crontrol plugin named hook_name: woocommerce_scheduled_subscription_payment .

in the WP Crontrol panel, you have the option to pass arguments - I tried adding $subscription_id (what the code would ask for), but did nothing.

So the question is, how can I get this cron job to handle everything in db? What bit of configuration am I missing?

thanks

DISCLAIMER: I inherited this from a client who supported him on his own. That was so when I got here, guv!

+5
source share
1 answer

According to the WooCommerce Git Repo Subscription Manager , this is the function that he is trying to run:

 /** * Sets up renewal for subscriptions managed by Subscriptions. * * This function is hooked early on the scheduled subscription payment hook. * * @param int $subscription_id The ID of a 'shop_subscription' post * @since 2.0 */ public static function prepare_renewal( $subscription_id ) { $order_note = _x( 'Subscription renewal payment due:', 'used in order note as reason for why subscription status changed', 'woocommerce-subscriptions' ); $renewal_order = self::process_renewal( $subscription_id, 'active', $order_note ); // Backward compatibility with Subscriptions < 2.2.12 where we returned false for an unknown reason if ( false === $renewal_order ) { return $renewal_order; } } 

You can see from this that it should get one parameter, which is an integer and must match the shop_subscription identifier.

So, here are a few things you are going to do to get this right. I proceed from the assumption that you do not want to dig too much in command line debugging, so as not to accidentally run cron jobs that can potentially change the situation in an unexpected way (this is usually a good idea when it can be avoided, especially when it involves other peoples money )

  • First, make sure your error log is enabled using define( 'WP_DEBUG_LOG', true );
  • Secondly, you need to write the value of $subscription_id as it exists when it is passed to the job.

Something like this in hook woocommerce_scheduled_subscription_payment :

 error_log(sprintf('Parameter [%s] with type [%s] is the [$subscription_id], as passed to the job: [%s]', (string) $subscription_id, gettype( $subscription_id), 'WC_Subscriptions_Manager::prepare_renewal' ) ); 

This should pick up the identifier that is being transmitted and put it in its error log. Then wait until the task starts again or starts manually.

After completing the assignment, you need to check the following things:

  • A message appeared in your journal (duh)
  • The value of $subscription_id is an integer and is not null or false.
  • The value of $subscription_id corresponds to a valid shop_subscription message in your database.

This is probably in your posts table, but Woo is known to sometimes do some things in the database, so if you can't find it in posts , use the following query to find this:

 SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'shop_subscription' AND TABLE_SCHEMA='YourDatabase'; 

You may need to play around with the header above to get the correct field, but between PhpMyAdmin or another MySql visualization tool and the INFORMATION_SCHEMA.COLUMNS query, you won’t have to find it for so long.

If you confirm that you have confirmed that you are passing a valid identifier, so if it is still broken, your next step is to return Woo from the actual function and find out why it does not provide a value.

This delves a bit into the internal functions of Wordpress, so make sure you back up your site before using the Git or tar file or something else so that you don’t leave any hacks in the kernel or plugin. If it is still broken, start the backup at this point before proceeding.


The following, if you have not yet found the actual problem, is to enter the WC_Subscriptions_Manager::prepare_renewal and register two things from there (see the reposition link at the top of this answer to help jump). You want to register print_r( debug_backtrace(), 1) in order to register a complete back trace from Woo back (it will be big, don't leave it there when you finish if you don't like massive log files that clutter up your entire disk space).

You will also want to register the value of $subscription_id directly inside this method to ensure that it is the same value that it passed.

From the views of your mistake, it seems that it is not transmitted at all. This most likely indicates that you received a null result from the database or hook, and your problem should be resolved in the first part of this diagnosis. The second part is redundancy to ensure that you really fixed the problem.

  • The task must be performed for each step that changes the code. Wait for the next run, run it manually, or run dryrun if possible to help with debugging.

If the previous developer hacked the Woo plugin, you can use Git to completely hide all its changes by following these steps:

 cd /path/to/plugin git init git add --all git remote add origin git@github.com :wp-premium/woocommerce-subscriptions.git git commit git pull 

then git diff one of the stable release commits from the github page. Any changes will be displayed in diff

This should cover quick debugging of the job, as well as highlighting any other problems with balances that you may have left with the previous developer, which you may not even know about yet.

+2
source

Source: https://habr.com/ru/post/1273579/


All Articles