![](/img/trans.png)
[英]Customize “Add to cart” button for a specific product category in WooCommerce
[英]Customize Add to Cart button on specific WooCommerce product categories
我試圖將WooCommerce存檔頁面上特定產品類別的“添加到購物車”按鈕更改為“更多”按鈕,該按鈕將鏈接到產品頁面( 但不在單個產品頁面上) 。
(Woocommerce,在Wordpress上使用Elementor)
使用“ 使用WooCommerce 3中的商店頁面上具有鏈接到產品頁面的更多信息替換添加到購物車按鈕 ”的答案代碼,如何將其限制為僅一個產品類別(在這種情況下,術語名稱為“類別”) ?
任何幫助表示贊賞。
您可以通過has_term()
方式使用has_term()
條件函數來定位產品類別:
add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
function replacing_add_to_cart_button( $button, $product ) {
if ( has_term( 'Classes', 'product_cat', $product->get_id() ) ) {
$button_text = __("Read more", "woocommerce");
$button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
}
return $button;
}
代碼在您的活動子主題(或活動主題)的functions.php文件中,或者在任何插件文件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.