What is the best way to override the woocomerce function that is in defined in the woocomerce plugins directory inside some class.
For example I am wanted to change the function start_el
declared in the class WC_Product_Cat_List_Walker
. I can change the function code in the plugin directory by the changes remains until I upgrade the woocomerce plugin.
How can I override it in my theme functions.php
file?
2 comments
Comments are closed.
try this…
you can create a class and extend to WC_Product_Cat_List_Walker.
then use it as like:
First, simply try copying
/includes/walkers/class-product-cat-list-walker.php
into your theme and include the new file. It may be pluggable and you can simply edit it there directly without any other effort. I’m not 100% sure.If that fails, then you can do it by filtering
woocommerce_product_categories_widget_args
and supplying your own walker instead of trying to edit WooCommerce’s.Leave your duplicated walker file in place, but rename all the class names from
WC_Product_Cat_List_Walker
toSO_Product_Cat_List_Walker
.And then in your theme’s
functions.php
tell the widget to use this new class as the appropriate Walker.