gpt4 book ai didi

wordpress - 如何获取更新的 WooCommerce 订单数据?

转载 作者:行者123 更新时间:2023-12-04 07:23:53 25 4
gpt4 key购买 nike

如何在此功能中访问更新的订单数据?我 super 困惑。
我找到了这个代码 here .

add_action ('save_post_shop_order',
function (int $postId, \WP_Post $post, bool $update): void{
// Ignore order (post) creation
if ($update !== true) {
return;
}

// Here comes your code...
},10,3);
提前致谢。

最佳答案

WordPress Hook
如果你想运行这个函数,你可以使用 edit_post_{$post->post_type} 仅在帖子更新时触发的钩子(Hook)。

// run a function when the WooCommerce order is updated
add_action( 'edit_post_shop_order', 'edit_post_shop_order_callback', 99, 2 );
function edit_post_shop_order_callback( $post_ID, $post ) {

// gets the WC_Order object
$order = wc_get_order( $post_ID );

// get the data you want
$order_status = $order->get_status();
$billing_first_name = $order->get_billing_first_name();
// ...

}
该代码已经过测试并且可以工作。将它添加到您的事件主题的functions.php。
WOOCOMMERCE Hook
否则你可以使用 woocommerce_update_order WooCommerce 钩子(Hook)。
// run a function when the WooCommerce order is updated
add_action( 'woocommerce_update_order', 'woocommerce_update_order_callback', 99, 1 );
function woocommerce_update_order_callback( $order_id ) {

// gets the WC_Order object
$order = wc_get_order( $order_id );

// get the data you want
$order_status = $order->get_status();
$billing_first_name = $order->get_billing_first_name();
// ...

}
该代码已经过测试并且可以工作。将它添加到您的事件主题的functions.php。
相关答案
  • Woocommerce hook for order update
  • 关于wordpress - 如何获取更新的 WooCommerce 订单数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68321252/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com