2017-02-23 84 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