I am newbie at PHP.
I am trying to check if the user has a payment token or some other value that confirms they have made a payment.
I want to redirect the page if the payment status is empty 9they have not made payment yet).
I tried :
<?php
if(get_post_type()=="sfwd-lessons"){
$lesson_id=get_the_ID();
}else{
$lesson_id=get_post_meta(get_the_ID(),'lesson_id',true);
}
$value = get_field( "new_field", $lesson_id );
$user_status=get_wpmg_woocommerce_payment_tokens($user_id,'token_id',true);
//$user_status='';
if(!empty($value) && empty($user_status)){
header('Location: https://xx/checkouts/checkout-page/');
exit;
?>
but I dot think "get_wpmg_woocommerce_payment_tokens" is a valid call
is there another get_ call I can make to check if payment token_id is empty for that user?
or is there a way on the woo commerce thank you page to write new field "payment_status" complete to user_meta_data
thanks
CodePudding user response:
This hook woocommerce_thankyou
will fire each time you refresh the thankyou page.
add_action('woocommerce_thankyou', 'after_order_placed', 10, 1);
function after_order_placed($order_id) {
if (!$order_id)
return;
$order = wc_get_order($order_id);
if ($order->get_date_paid()) {
// Order is paid - Do something
} else {
// Order is NOT paid - Do something else
}
}
The best hook for sending some data to a third party when order payment is completed is woocommerce_payment_complete
.
add_action('woocommerce_payment_complete', 'after_payment_complete');
function payment_complete_callback($order_id) {
if (!$order_id)
return;
$order = wc_get_order($order_id);
if ($order->get_date_paid()) {
// Order is paid - Do something
} else {
// Order is NOT paid - Do something else
}
}
CodePudding user response:
Hi @aidan545 it's already resolved you can check from the below link in the link it will give you a proper way for accessing all the order details with woocommerce object WC_Order