php – too few arguments to make woocommerce_update_product_acf_save_post() work

I have an action in my functions.php to notify customers of a product update. I have a working function that accepts 2 arguments ($product_id and $product). However when I press update on a product an e-mail goes out with the old values ​​of my ACF.

add_action('woocommerce_update_product', 'action_on_product_save', 20, 2);

function action_on_product_save($product_id, $product) {
    $updating_product_id = 'update_product_' . $product_id;
    if (false === ($updating_product = get_transient($updating_product_id))) {

I found a topic from someone with the same issue, but this solution won’t accept 2 arguments for some reason (probably my fault).

This is the code I found online that works if I further down all the $product related stuff. So with the code below my e-mail shows the updated ACF directly. However without the product name I cannot add the $product argument without getting a fatal error (see below)

add_action('acf/save_post', 'woocommerce_update_product_acf_save_post', 1000, 1);

function woocommerce_update_product_acf_save_post( $product_id ) {
    if (get_post_type($product_id) == "product") {
        remove_action('acf/save_post', 'woocommerce_update_product_acf_save_post');
        update_on_product_save( $product_id );
    }
}


function update_on_product_save($product_id) {

when i add the second argument (change the i argument value to 2 below)

add_action('acf/save_post', 'woocommerce_update_product_acf_save_post', 1000, 2);

function woocommerce_update_product_acf_save_post( $product_id, $product ) {
    if (get_post_type($product_id) == "product") {
        remove_action('acf/save_post', 'woocommerce_update_product_acf_save_post');
        update_on_product_save( $product_id, $product );
    }
}

function update_on_product_save($product_id, $product ) {

I get an error;

Uncaught ArgumentCountError: Too few arguments to function woocommerce_update_product_acf_save_post(), 1 passed in /home/domain/public_html/wp-includes/class-wp-hook.php on line 307 and exactly 2 expected in /home/domain/public_html/wp-content/themes/hello-elementor-child/functions.php:50, referer: https://www.domain.com/wp-admin/post.php?post=7398&action=edit

Leave a Comment