0

I am trying to get these parameters from the do_action placed inside body:

do_action( 'custom_action',  array( 'product_id' => $product_id ,  'outbiddeduser_id' => $outbiddeduser, 'log_id' => $log_id ) );

I am trying to do it like this:

    add_action('custom_action', 'test', 10, 3);
    function test($product_id, $outbiddeduser_id, $log_id) {
         $a = $product_id;
         $b = $outbiddeduser_id;
         $c = $log_id; 

     echo $a . ', ' . $b . ', ' . $c;
    }

And this:

add_action('custom_action', 'test', 10, 1);
function test( $associative_array ) {
   $a = $associative_array['product_id'];
   $b = $associative_array['outbiddeduser_id'];
   $c = $associative_array['log_id'];

   echo $a . ', ' . $b . ', ' . $c;
}

And it's not working. What am I doing wrong?

3
  • How are you testing this? The code examples as is don't have any means of checking if it worked or not Commented Sep 3, 2019 at 17:40
  • Updated it again. Commented Sep 3, 2019 at 19:31
  • I see, if you don't get what you expected, what do you get instead? And can you update your code so it has values? There are variables, but it's unclear what their values are, which means it might work but it's getting empty values Commented Sep 4, 2019 at 13:54

1 Answer 1

0

You passed the action an associative array, so your hooked function will recieve an associative array. It's a little clearer if we retype it like this:

$associative_array = array(
    'product_id' => $product_id ,
    'outbiddeduser_id' => $outbiddeduser,
    'log_id' => $log_id
);
do_action( 'woocommerce_simple_auctions_outbid',  $associative_array );

Thus:

add_action('woocommerce_simple_auctions_outbid', 'test', 10, 1);
function test( $associative_array ) {

It comes in as an array, because that's what you passed through. There's no magic unpacking of the array in do_action

2
  • I forgot to mention that I also tried what you suggested. Commented Sep 3, 2019 at 17:32
  • I edited my question now. Commented Sep 3, 2019 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.