将自定义参数添加到 Paypal Woocommerce [英] Adding custom args to Paypal Woocommerce

查看:82
本文介绍了将自定义参数添加到 Paypal Woocommerce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向 PayPal 付款链接添加自定义参数.

I need to add custom args to PayPal paying link.

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 没有显示.

I added txn_type and invoice as arguments to the link. But payment_date is not shown.

可能是什么问题?另外,如何显示客户的电子邮件?

What may be the problem? Also, how can I display email of the customer?

推荐答案

如果您启用了 WP_DEBUG,您可能会看到 $order_id 未定义,因此 $order 不是订单对象,所以 $order->order_date 可能是一个致命错误.尝试将订单作为第二个参数传递.

If you enabled WP_DEBUG you would probably see that $order_id is undefined, and therefore $order is not an order object, so $order->order_date is likely a fatal error. Try passing the order as the second parameter instead.

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

这篇关于将自定义参数添加到 Paypal Woocommerce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆