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 questionI 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 questionI 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.
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);