Edit HTML of woo commerce featured products widget

萝らか妹 提交于 2019-12-24 02:23:37

问题


I want to modify HTML code of woo-commerce featured product widget. Problem is that I can't find it inside my template folder/plugin folder.

Does someone knows how to modify featured product widget of woo-commerce?


回答1:


This is modified via the content-widget-product.php template, located in /woocommerce/templates/.

To override this template, copy: woocommerce/templates/content-widget-product.php to yourtheme/woocommerce/content-widget-product.php, and make any necessary modifications in the copied file (not the original).

For information on correctly modifying Woocommerce templates, please see the docs on overriding WooCommerce templates.




回答2:


I've done this with random products, but you can change whatever class you want, just change the file names...

add to functions.php

add_action( 'widgets_init', 'err_override_woocommerce_widgets', 15 );
function err_override_woocommerce_widgets() {
    if ( class_exists( 'WC_Widget_Random_Products' ) ) {
        unregister_widget( 'WC_Widget_Random_Products' );
        include_once( 'woocommerce/classes/class-wc-widget-random-products.php' );
        register_widget( 'err_WC_Widget_Random_Products' );
    }
}   

Note: don't forget to change the path, which is relative to functions.php!

Copy

wp-content/plugins/woocommerce/classes/widgets/class-wc-widget-random-products.php

to

wp-content/templates/%theme name%/woocommerce/classes/class-wc-widget-random-products.php

Note: change %theme name% to your theme name!

Add the widget to your sidebar/footer/etc, change anything in your class in it's new place, and you're done.



来源:https://stackoverflow.com/questions/27215984/edit-html-of-woo-commerce-featured-products-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!