I’m working in WordPress here. I have the following code:
if (is_product() && is_woocommerce() && $this->category_has_fiance() == true) {
$tabs['finance_tab'] = array(
'title' => __( 'Finance Options', 'woocommerce' ),
'priority' => 50,
'callback' => array ($this, 'woo_finance_tab_content')
);
return $tabs;
}
This works as you’d expect, and calls the $woo_finance_tab_content
. However, I’d like to pass some arguments to $woo_finance_tab_content
tab. Is this possible with this scenario?
The
woocommerce_product_tabs
filter is usingcall_user_func
function to process the callback:So actually it is sending two parameters to the callback: the key (so in your case
finance_tab
) and the whole tab array. So, theoretically, you should be able to do this:Then:
Unfortunately not.
The arguments available in a callback like this will only be the arguments defined by the callback.
See if the data you want is available in the arguments passed to the callback already, as they often will be.
Ok so this is possible (it’s a little hacky).
As @vard suggested declare the tab like this:
Now in the tab function (I.E the function defined in callback), do the following:
The var dump will display “stuff”. Clearly useless here, but this could also be an extremely useful array. Hopefully this will come in useful to someone!
I was able to pass an array as argument like this:
the tab_arr will have image_ids