I’m trying to redirect to a specific page after WooCommerce checkout page if the user check the checkbox.

The checkbox:

woocommerce_form_field( 'checkbox_yes', array(
'type'          => 'checkbox',
'class'         => array('form-row-wide'),
'label'         => __('Yes'),
), $checkout->get_value( 'checkbox_yes'));

And redirection:

add_action( 'template_redirect', 'wc_redirect_after_checkout' ); 
function wc_redirect_after_checkout() {
  global $wp;
  if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
    if ( isset( $_POST['checkbox_yes'] ) && $_POST['checkbox_yes'] == 1 ) 
    wp_redirect( 'http://SomeDomain.com/' );
  }
}

When I tried this code, it didn’t redirect to that URL, but it work properly without the second if statement of checkbox! What I did wrong, please any help?

Read more here: redirect to a custom URL after checkout based on checkbox value


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: