我使用Mystile WooCommerce主题,其中“添加到购物车”按钮由以下代码删除:
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);放置在此文件wp-content/themes/mystile/includes/theme-woocommerce.php中的
我知道我可以删除这段代码,但是在下一次更新后更改theme-woocommerce.php文件之后,是否有一个选项,所以按钮仍然会出现呢?
我已经尝试在子主题中将此代码添加到我的functions.php中。
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10); 发布于 2013-11-24 13:58:39
您没有在主题文件中这样做是正确的,您也有正确的想法将其放入您的functions.php中。尝试下面所示的方法,这是您实际需要的更多,所以选择适合您的情况。
//remove add to cart buttons
add_action( 'init', 'wpse124288_wc_remove_add_to_cart_buttons' );
function wpse124288_wc_remove_add_to_cart_buttons() {
//add to cart button loop
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
//add to cart button single product
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
//(re)add add to cart buttons
add_action( 'init', 'wpse124288_wc_readd_add_to_cart_buttons' );
function wpse124288_wc_readd_add_to_cart_buttons() {
//add to cart button loop
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
//add to cart button single product
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}https://wordpress.stackexchange.com/questions/124288
复制相似问题