如何在WooCommerce中获得Paypal交易ID?

时间:2016-01-08 14:46:15

标签: php wordpress paypal woocommerce

我试图在thankyou.php页面上获取交易ID,但WC_Order对象没有PayPal transcation 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] => 
)

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

2 个答案:

答案 0 :(得分:3)

交易ID是后期元数据的一部分......

$ transaction_id = get_post_meta($ order_id,'_ tranaction_id',true);

答案 1 :(得分:0)

最好通过API:

global $woocommerce;

//Retrieve the order
$order = new WC_Order($order_id);

//Retrieve the transaction ID
$transID = $order->get_transaction_id();