I have a php function called wc_print_notices
that is in the core files of woocommerce, and I don’t wish to edit the core files if I can avoid it.
So I would like to write something in my functions.php file that will add more functionality to this function.
I’ve tried using filters, however, those only work with woocommerce functions that act as hooks, and this is a function that is called through a hook, so do_action()
and add_filter
do not work with wc_print_notices
I want to add related products to this function, and have tried something like this
function popup_products( $popup ){
$popup = woocommerce_output_related_products();
return $popup;
}
The function itself works perfectly, however, I want to add this to the function wc_print_notices
the filters I tried were:
add_filter( 'wc_print_notices', 'popup_products', 1, 1);
add_filter( 'wc_print_notices', 'popup_products', 99, 99);
add_filter( 'wc_print_notices', 'popup_products', 1);
add_filter( 'wc_print_notices', 'popup_products', 99);
Since wc_print_notices is being called by
add_action( 'woocommerce_before_shop_loop', 'wc_print_notices', 10 );
i think you need to remove that action withremove_action
thenadd_action( 'woocommerce_before_shop_loop', 'my_custom_wc_print_notices', 10 );
Maybe adding additional notices.
I think in your case if all you want to do is add additional information all you have todo is add it in one of the Woocommerce Loop’s.
add_action('woocommerce_before_shop_loop','popup_products');
With OP Clarification
I think the best bet is like i suggest before to remove the default
add_action
place it back with your modified version ofwc_print_notices
.