Himani
Himani

Reputation: 265

retrieving value from add_action in wordpress

I am trying to call an action inside the filter. I want to retrieve a value from the action method and use it for the filter function

   add_filter( 'wc_product_table_query_args', 'wcpt_custom_query_args', 10, 3 );

function wcpt_custom_query_args( $args, $product_table) {
add_action('dokan_store_profile_frame_after', 'add_store_id', 13, 2);
        ;

    // do something with $args
$args += array('author' => $store_id);

    return $args;
}

function add_store_id($store_user, $store_info){
    $store_id = $store_user->ID;    
    return $store_id;

}

How can I retrieve the $store_id inside the function wcpt_custom_query_args?

Upvotes: 2

Views: 2440

Answers (2)

Anand Choudhary
Anand Choudhary

Reputation: 565

    add_action('dokan_store_profile_frame_after', 'add_store_id', 13, 2);

function add_store_id($store_user, $store_info){
    global $store_id;
    $store_id = $store_user->ID;    
    add_filter( 'wc_product_table_query_args', 'wcpt_custom_query_args', 10, 2 );
}

function wcpt_custom_query_args( $args, $product_table) {
global $store_id;
    // do something with $args
$args += array('author' => $store_id);

    return $args;
}

Upvotes: 1

Trac Nguyen
Trac Nguyen

Reputation: 486

You should find in your source code the line apply_filter('wc_product_table_query_args' to look for the params allowed. If 3rd param is $store_id then you can use that.

One thing you should remember, on action hook, nothing should be returned (return only for filter hook)

Upvotes: 0

Related Questions