2017-09-18 57 views
1

我正在尝试调用过滤器中的操作。我想要从动作方法的值,并用它来过滤功能从wordpress中的add_action中检索值

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; 

} 

我怎样才能检索功能wcpt_custom_query_args里面的$ STORE_ID?

回答

1
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; 
} 
+0

全局不工作...我已经尝试过:( – Himani

+1

请先加载add_store_id之后比wcpt_custom_query_args funciton –

+0

非常感谢...通过加载add_store_id函数它工作:) :) :) – Himani

0

您应该在您的源代码中找到apply_filter('wc_product_table_query_args'行以查找允许的参数。如果第三参数是$ store_id,那么你可以使用它。你应该记住,行动挂钩

一两件事,没有什么应退还(只返回筛选器挂钩)

+0

apply_filter(“wc_product_table_query_args”由只有两个参数,其中没有一个是$ STORE_ID – Himani

+0

你能尝试var_dump $ args,$ product_table来查看任何参数可用于获取$ store_user和$ store_id? –

+0

不能从这些参数猜测 – Himani