im trying to change order status to “completed” and skip payment page (go to thank you page) after order is processed.
so far i manage to change order status to completed but instead of redirecting me to thank you page, i will be redirected to payment page with the following error :
this is the code i use :
add_filter( 'woocommerce_checkout_order_processed' , 'skip_join_payment' );
function skip_join_payment( $order_id ) {
if ( ! $order_id ) {
return;
}
if( $_COOKIE['isjoinForFree'] == "yes" ){
$order = wc_get_order( $order_id );
$order->update_status( 'completed' );
** i tried to redirect here but getting error on checkout page **
// if ( $order->has_status( 'completed' ) ) {
// header("Location: /jtnx/");
// die();
// }
}
}
in addition i tried adding another hooks with redirect :
add_action( 'woocommerce_payment_complete', 'skiped_join_payment_redirect', 1 );
function skiped_join_payment_redirect ( $order_id ){
$order = wc_get_order( $order_id );
if( $_COOKIE['isjoinForFree'] == "yes" ){
$order = wc_get_order( $order_id );
if ( $order->has_status( 'completed' ) ) {
header("Location: /jtnx/");
die();
}
}
}