[英]woocommerce - Remove “Add to cart” button
僅隱藏“添加到購物車”按鈕而不影響其他東西(如變化下拉列表或數量)的正確方法是什么?
我在按鈕上使用display:none
找到了解決方案,但是可以繞開它。
我的目標是在某些產品上將“添加到購物車”按鈕替換為“索取價格”按鈕。
插件> woocommerce,然后打開文件woocommerce.php
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 );
此代碼將幫助您從商店頁面和產品詳細信息頁面隱藏“添加到購物車”按鈕
要僅隱藏“ 添加到購物車 ”-
function remove_loop_button(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
}
add_action('init','remove_loop_button');
add_action('woocommerce_after_shop_loop_item','replace_add_to_cart');
function replace_add_to_cart() {
global $product;
$link = $product->get_permalink();
echo do_shortcode('<a href="'.$link.'" class="button addtocartbutton">Request price</a>');
}
它將在“商店”頁面中刪除每個產品的“添加到購物車”按鈕。
在這里你可以得到WooCommerce行動和篩選器掛鈎- https://docs.woothemes.com/wc-apidocs/hook-docs.html
您好,這是您的解決方法代碼。 您需要使用不影響其他代碼的鈎子。 這將從所有產品中刪除“添加到購物車”按鈕。
function remove_loop_button(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
add_action('init','remove_loop_button');
下面是代碼,如果您要更改添加到購物車按鈕文本,可以使用該代碼。
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' ); // < 2.1
function woo_custom_cart_button_text() {
return __( 'My Button Text', 'woocommerce' );
}
我希望這能幫到您。
function remove_loop_button(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
add_action('init','remove_loop_button');
該代碼對我有用。
如果失敗,我去了plugins / woocommerce中的wc-template-hooks.php以評論以下內容:
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
我希望這能對某人有所幫助,但我遇到了一個名為Rango的主題,無論如何它顯示了重復添加到購物車按鈕的問題……我不得不進入wp-content / themes / rango / inc / woo /有一個名為hooks.php的文件,我注釋了add_action('woocommerce_after_shop_loop_item', 'ftc_template_loop_add_to_cart', 80);
那對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.