PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, May 10, 2022

[FIXED] Which available hook after products bulk save is completed in Woocommerce

 May 10, 2022     hook-wordpress, php, product, woocommerce, wordpress     No comments   

Issue

I have customized the bulk edit functionality using

add_action('woocommerce_product_bulk_edit_start', function () {
    // ...
}, 10, 0);

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

I would like to do some further processing after all products have been saved. Is there a hook I can tie into for that?

Any pointers are welcome.

Clarification: I do need to access all information sent in the bulk edit request (bulk edit field values, product ids, etc.).


Solution

You could use Wordpress admin_init action hook like in this example, where a custom message is displayed after products have been saved:

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>';
}

Code goes in function.php file of your active child theme (active theme). Tested and works.

enter image description here

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"

Note:

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



Answered By - LoicTheAztec
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing