在 Woocommerce 中完成产品批量保存后可用的挂钩

Which available hook after products bulk save is completed in Woocommerce

我使用

自定义了批量编辑功能
add_action('woocommerce_product_bulk_edit_start', function () {
    // ...
}, 10, 0);

add_action('woocommerce_product_bulk_edit_save', function ($product) {
    // ...
}, 10, 1);

我想在保存所有产品后做一些进一步的处理。有没有我可以系上的钩子?

欢迎指点。

澄清:我确实需要访问批量编辑请求中发送的所有信息(批量编辑字段值、产品 ID 等)。

您可以像本例中那样使用 Wordpress admin_init 操作挂钩,其中在保存产品后显示自定义消息:

add_action( 'admin_init', 'after_bulk_edit_products_save' );
function after_bulk_edit_products_save() {
    global $pagenow;

    if( $pagenow === 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] === 'product'
    && isset($_GET['paged']) && ( isset($_GET['updated']) || isset($_GET['skipped']) || isset($_GET['locked']) ) ) {
        add_action( 'admin_notices', 'custom_bulk_action_admin_notice' );
    }
}

function custom_bulk_action_admin_notice() {
    echo '<div id="message" class="updated"><p>This is a custom message displayed after save</p></div>';
}

代码进入您的活动子主题(活动主题)的 function.php 文件。已测试并有效。

You can access from $_GET the following variables (always use isset() to avoid errors):

  • $_GET['post_type'] - the post type which is "product"
  • $_GET['paged'] - default value is "1" most
  • $_GET['updated'] - the number of products "updated"
  • $_GET['skipped'] - the number of products "skipped"
  • $_GET['locked'] - the number of products "locked"

注:

You have access to all the data submitted for bulk edit (and quick edit) in the $_REQUEST global.