【问题标题】:How to get Paypal Transaction ID in WooCommerce?如何在 WooCommerce 中获取 Paypal 交易 ID?
【发布时间】:2016-04-13 07:02:14
【问题描述】:

我正在尝试在thankyou.php 页面上获取交易ID,但WC_Order 对象没有paypal 交易ID。

WC_Order 对象:-

WC_Order Object
(
    [order_type] => simple
    [id] => 49
    [post] => WP_Post Object
        (
            [ID] => 49
            [post_author] => 1
            [post_date] => 2016-01-08 13:55:24
            [post_date_gmt] => 2016-01-08 13:55:24
            [post_content] => 
            [post_title] => Order – January 8, 2016 @ 01:55 PM
            [post_excerpt] => 
            [post_status] => wc-pending
            [comment_status] => open
            [ping_status] => closed
            [post_password] => order_568fbfcc2b0f2
            [post_name] => order-jan-08-2016-0155-pm
            [to_ping] => 
            [pinged] => 
            [post_modified] => 2016-01-08 13:55:24
            [post_modified_gmt] => 2016-01-08 13:55:24
            [post_content_filtered] => 
            [post_parent] => 0
            [guid] => http://localhost/lfdemo/?post_type=shop_order&p=49
            [menu_order] => 0
            [post_type] => shop_order
            [post_mime_type] => 
            [comment_count] => 0
            [filter] => raw
        )

    [order_date] => 2016-01-08 13:55:24
    [modified_date] => 2016-01-08 13:55:24
    [customer_message] => 
    [customer_note] => 
    [post_status] => wc-pending
    [prices_include_tax] => 
    [tax_display_cart] => excl
    [display_totals_ex_tax] => 1
    [display_cart_ex_tax] => 1
    [formatted_billing_address:protected] => 
    [formatted_shipping_address:protected] => 
)

我需要一些帮助!所以请发表评论并提供解决方案!

【问题讨论】:

  • 你什么时候拉这个订单对象的?它显示状态为待处理。在 IPN 触发之前,交易 ID 不会返回到订单中,这发生在付款完成之后。你确定你不只是过早地检查它吗?
  • 谢谢安德鲁。我在 PayPal IPN 中编写触发器,而不是在 WooCommerce 中编写。
  • 你整理好了吗?我也在寻找解决方案。

标签: php wordpress paypal woocommerce


【解决方案1】:

事务 ID 是帖子元数据的一部分...

$transaction_id = get_post_meta($order_id, '_transaction_id', true);

【讨论】:

    【解决方案2】:

    最好通过 API:

    global $woocommerce;
    
    //Retrieve the order
    $order = new WC_Order($order_id);
    
    //Retrieve the transaction ID
    $transID = $order->get_transaction_id();
    

    【讨论】:

      猜你喜欢
      • 2016-04-17
      • 2012-01-26
      • 2020-09-19
      • 2019-12-21
      • 2020-10-14
      • 2014-11-09
      • 1970-01-01
      • 2015-11-06
      • 2023-03-21
      相关资源
      最近更新 更多