Answer the question
In order to leave comments, you need to log in
How to add class to WooCommerce category list?
How can I add a class to the category list widget?
I found a file where all this is created (class-wc-widget-product-categories.php), but since this is a core file, it is clear that when woocommerce is updated, all changes will be lost.
Perhaps this can be done using filters?
Tell me please. <ul class="product-categories">
Answer the question
In order to leave comments, you need to log in
One way to solve the problem is to override the WC_Widget_Product_Categories class method.
To do this, create the file [current_theme]/widgets/widget-product_categories.php
Place the code of the overridden method there
class Custom_WC_Widget_Product_Categories extends WC_Widget_Product_Categories {
function widget( $args, $instance ) {
// скопировать весь код метода из:
// woocommerce/includes/widgets/class-wc-widget-product-categories.php
// добавить нужный класс в строке с выводом открывающего тега списка
echo '<ul class="product-categories <b>my-class</b>">';
}
}
/**
* WC_Widget_Product_Categories widget override
*/
add_action( 'widgets_init', 'override_woocommerce_widgets', 15 );
function override_woocommerce_widgets() {
if ( class_exists( 'WC_Widget_Product_Categories' ) ) {
unregister_widget( 'WC_Widget_Product_Categories' );
include_once( 'widgets/widget-product_categories.php' );
register_widget( 'Custom_WC_Widget_Product_Categories' );
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question