我正在寻找解决我问题的方法。我想根据WooCommerce订单总额更改PayPal电子邮件。
因此,如果订单总额<10 $
其他
我尝试在此处搜索,发现的唯一代码是:
add_filter( 'woocommerce_paypal_args', 'woocommerce_paypal_args', 10, 2 );
function woocommerce_paypal_args( $paypal_args, $order ) {
//Get the customer ID
$user_id = $order->get_user_id();
// Get the user data
$user_data = get_userdata( $customer_id );
// Adding an additional recipient for a custom user role
if ( in_array( 'wholesale_customer', $user_data->roles ) )
$paypal_args['business'] = '[email protected]';
return $paypal_args;
}
但是这里不是基于WooCommerce订单总数,而是基于用户角色。有什么个性化的方法吗?
woocommerce_paypal_args
有两个参数,设置和$order
对象。因此,根据订单,我们可以获取总计,并基于此更改电子邮件
function filter_woocommerce_paypal_args( $paypal_args, $order ) {
// Get total
$order_total = $order->get_total();
// Less then 10
if ( $order_total < 10 ) {
$paypal_args['business'] = '[email protected]';
} else {
$paypal_args['business'] = '[email protected]';
}
return $paypal_args;
}
add_filter( 'woocommerce_paypal_args', 'filter_woocommerce_paypal_args', 10, 2 );
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句