$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>WooCommerce subscriptions give option of manual renewal on checkout|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

WooCommerce subscriptions give option of manual renewal on checkout

matteradmin10PV0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I am trying to figure out how I can offer the option of manually renewing (automatic by default) a subscription on the checkout page. I would ideally like this to be a checkbox on the checkout page which is ticked by default saying 'automatically renew subscription'.

I can't seem to find any information on doing this so any input will be greatly appreciated.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I am trying to figure out how I can offer the option of manually renewing (automatic by default) a subscription on the checkout page. I would ideally like this to be a checkbox on the checkout page which is ticked by default saying 'automatically renew subscription'.

I can't seem to find any information on doing this so any input will be greatly appreciated.

Share Improve this question asked Feb 7, 2019 at 11:13 AppleTattooGuyAppleTattooGuy 1051 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Having done something similar recently:

Step 1: Add your checkbox as a custom checkout field (not covered here, you can easily find guides on how to do this).

Step 2: When the user submits their order at checkout, look for the manual renewal value in the submitted checkout data, and set it as meta on the WooCommerce order.

add_action('woocommerce_checkout_update_order_meta',function( $order_id) {    
    if(!empty($_POST['custom_manual_renewal'])){
        update_post_meta($order_id,'custom_manual_renewal',1);
    }
});

Step 3: When your subscription is created shortly after the order, look for your piece of meta and maybe set the subscription to manual.

add_action('woocommerce_checkout_subscription_created', function($subscription, $order){
    if(get_post_meta($order->get_id(),'custom_manual_renewal',true)){
        $subscription->update_manual(true); //set subscription to be manual renewal
    }
},10,2);
Post a comment

comment list (0)

  1. No comments so far