【问题标题】:WordPress - woocommerce_process_shop_order_meta doesn´t workWordPress - woocommerce_process_shop_order_meta 不起作用
【发布时间】:2021-09-13 13:00:45
【问题描述】:

我试图在订单更新后包含一个功能(管理端),但它不起作用。当有人更新订单(订单状态等)时,我想调用一个函数。我正在尝试这个:

add_action( 'woocommerce_process_shop_order_meta', 'woocommerce_process_shop_order', 1, 1);
function woocommerce_process_shop_order () {
    // Code
}

我一直在尝试使用header("Location: www.example.com") 重定向到其他网站,但是当订单更新时页面不会重定向:(

拜托,你能帮我解决一下吗?

谢谢!

【问题讨论】:

  • 错误的钩子。由于订单是 WP 帖子,您可以使用 post_updated 挂钩。检查我的答案。

标签: wordpress woocommerce plugins hook


【解决方案1】:

你去。测试和工作。进入您的子主题的functions.php 文件:

add_action( 'post_updated', 'post_updated_action', 20, 3 );
function post_updated_action( int $post_id, WP_Post $post_after, WP_Post $post_before ): void {
    // To be sure it gets called when updated from the admin dashboard and is order
    if ( $post_before->post_type !== 'shop_order' || ! is_admin() ) {
        return;
    }

    wp_safe_redirect( home_url() );
    exit;
}

【讨论】:

    猜你喜欢
    • 2012-05-03
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多