2017-02-23 83 views
0

我需要將自定義參數添加到PayPal支付鏈接。向Paypal添加自定義參數Woocommerce

PHP函數看起來像這樣:

$paypal_args = apply_filters('woocommerce_paypal_args', $paypal_args); 
add_filter('woocommerce_paypal_args' , 'change_paypal_args'); 

function change_paypal_args($paypal_args) { 
    global $wp; 
    global $woocommerce; 
    $order = wc_get_order($order_id); 

    $paypal_args['invoice'] = 'spi432'; 
    $paypal_args['txn_type'] = 'cart'; 
    $paypal_args['payment_date'] = $order->order_date; 

    return $paypal_args; 
} 

我加入txn_typeinvoice作爲參數的鏈接。但是沒有顯示payment_date

可能是什麼問題?另外,如何顯示客戶的電子郵件?

+0

不顯示在哪裏?顯示客戶電子郵件在哪你的問題不清楚。同時檢查[PayPal文檔](https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/)。 'payment_date'甚至是支持的參數嗎?順便說一下,您可以刪除代碼的第一行。 '$ paypal_args = apply_filters('woocommerce_paypal_args',$ paypal_args);'沒有做任何事情。 – helgatheviking

+0

在生成woo的url中。示例:https://www.paypal.com/cgi-bin/webscr?cmd = _cart&business = paypal%40west.com&no_note = 1&currency_code = USD ... +我的其他參數 –

回答

1

如果啓用WP_DEBUG您可能會看到$order_id未定義,因此$order不是訂單對象,因此$order->order_date可能是致命錯誤。嘗試將訂單作爲第二個參數傳遞。

add_filter('woocommerce_paypal_args' , 'so_42424283_change_paypal_args', 10, 2); 

function so_42424283_change_paypal_args($paypal_args, $order) { 

    $paypal_args['invoice'] = 'spi432'; 
    $paypal_args['txn_type'] = 'cart'; 

    // WC 2.6+ 
    $paypal_args['payment_date'] = $order->order_date; 

    // WC 2.7 
    //$paypal_args['payment_date'] = $order->get_date_created(); 

    return $paypal_args; 
} 
+0

工作,謝謝。但仍不能收到客戶的電子郵件。嘗試$ paypal_args ['payer_email'] = $ order_meta ['_ billing_email'] [0]; - 調試中沒有任何信息。 –

+0

剛更改爲$ order-> billing_email;它的工作原理。萬分感謝。你能說 - 是否可以重命名參數?例如,將amount_1更改爲mc_gross。 –

+0

重命名參數?我不明白你的意思。 PayPal需要特定的參數,但您可以更改其值。 – helgatheviking