你没有在主题文件中这样做是对的,你也有正确的想法,把它放进你的functions.php
. 尝试下面所示的方法,它更符合您的实际需要,因此请选择适合您的情况的方法。
Code:
//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 );
}