add_action( 'woocommerce_before_email_order', 'add_order_instruction_email', 10, 2 );
function add_order_instruction_email( $order, $sent_to_admin ) {
if ( ! $sent_to_admin ) {
if ( 'cod' == $order->payment_method ) {
// cash on delivery method
echo '<p><strong>Instructions:</strong> Full payment is due immediately upon delivery: <em>cash only, no exceptions</em>.</p>';
} else {
// other methods (ie credit card)
echo '<p><strong>Instructions:</strong> Please look for "Madrigal Electromotive GmbH" on your next credit card statement.</p>';
}
}
}
/**
* Main instance of WooCommerce.
*
* Returns the main instance of WC to prevent the need to use globals.
*
* @since 2.1
* @return WooCommerce
*/
function WC() {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart');
return WooCommerce::instance();
}
添加代码后,保存文件并刷新页面。如果操作正确,应该会看到“添加到购物车”按钮已从页面中删除。
条件隐藏 WooCommerce 添加到购物车按钮
在某些情况下,如果只想隐藏特定产品的“添加到购物车”按钮。在这种情况下,需要使用条件方法。
隐藏特定产品的 Woocommerce 添加到购物车按钮
按照以下步骤隐藏特定产品的“添加到购物车”按钮:
导航至 WordPress 仪表盘 → 产品 → 所有产品。
将鼠标悬停在想要隐藏“添加到购物车”按钮的产品上,并记下产品 ID(在此示例中,ID 为 25)。
接下来,将以下代码添加到网站的functions.php文件中:
add_action( 'woocommerce_after_shop_loop_item', 'hide_add_to_cart_for_specific_product', 10 );
function hide_add_to_cart_for_specific_product() {
global $product;
if ( 25 == $product->get_id() ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
add_filter( 'woocommerce_is_purchasable', 'disable_add_to_cart_button' );
function disable_add_to_cart_button( $is_purchasable ) {
// You can add conditions here to disable the button for specific products
return false; // return false disables the 'Add to Cart' button
}