在 WooCommerce 中付款确认后添加自定义元数据 [英] Add custom meta data after Payment confirmation in WooCommerce
本文介绍了在 WooCommerce 中付款确认后添加自定义元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网上寻找解决方案来添加来自我正在使用的支付网关的响应.
I was looking around the web for a solution to add the response from the payment gateway I am using.
我想添加我获得的验证码和更多数据.付款完成后,我需要添加此项.
I would like to add the verification code I get and some more data. I need to add this once the payment is complete.
// Payment complete
$order->payment_complete($payment_id);
我确实尝试过此代码,但对我不起作用:
I did try this code but does not work for me:
add_action('woocommerce_checkout_update_order_meta',
'my_custom_checkout_field_update_order_meta');
function my_custom_checkout_field_update_order_meta( $order_id ) {
update_post_meta( $order_id, 'My Field', 'test');
}
任何帮助将不胜感激
推荐答案
你最好这样使用专用的 woocommerce_payment_complete 动作钩子:
You should better use dedicated woocommerce_payment_complete action hook this way:
add_action('woocommerce_payment_complete', 'custom_update_order_meta', 20, 1 );
function custom_update_order_meta( $order_id ) {
update_post_meta( $order_id, 'My Field', 'test');
}
代码位于活动子主题(或活动主题)的 function.php 文件中.
这应该有效.
对于插件,您需要先在 __construct()
函数中添加:
For A plugin you will need to add this first in the __construct()
function:
add_action('woocommerce_payment_complete', array( $this 'custom_update_order_meta'), 20, 1 );
然后是:
public function custom_update_order_meta( $order_id ) {
update_post_meta( $order_id, 'My Field', 'test');
}
这篇关于在 WooCommerce 中付款确认后添加自定义元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文