WooCommerce付款状态或令牌 - 如何获得_

发布于 2025-01-21 09:40:12 字数 755 浏览 0 评论 0原文

我是PHP的新手。

我正在尝试检查用户是否有付款令牌或其他一些确认他们已经付款的价值。

如果付款状态为空,我想重定向页面,他们尚未付款)。

我尝试过:

<?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;
    ?>

但是我认为“ get_wpmg_woocommerce_payment_tokens”是一个有效的调用

,我可以拨打另一个get_呼叫,我可以检查付款token_id是否为该用户为空?

还是在Woo Commerce上有办法谢谢您的页面,以编写新的字段“ pealdy_status”完整为user_meta_data

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千秋岁 2025-01-28 09:40:12

此挂钩woocommerce_thankyou每次刷新Thankyou页面时都会发射。

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
    }
}

完成订单付款后,将一些数据发送到第三方的最佳挂钩是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
    }
}

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
    }
}
行至春深 2025-01-28 09:40:12

HI @aidan545已经解决了您可以从链接中的以下链接中检查它,它将为您提供一种适当的方法,可以使用woocommerce对象wc_order链接访问所有订单详细信息

如何获取WooCommerce订单详细信息

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

Link: How to get WooCommerce order details

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文