由于某些原因,我想將鏈接從“添加到購物車”按鈕更改。因此,當在 archive-product.php 上時,此按鈕的鏈接不應進入添加到購物車頁面,而是進入單一產品頁面。(單一產品.php)
在 single-product.php 上時,該按鈕應鏈接到我將定義的另一個自定義頁面,但也不應鏈接到添加到購物車頁面。(這個用例我不需要)
我意識到,這必須是 functions.php 中的條件過濾器——但我不知道如何制作它。
我設法根據我所在的頁面更改按鈕文本。喜歡:
function woocommerce_custom_single_add_to_cart_text() {
return __( 'Produkt verhindern', 'woocommerce' );
}
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );
function woocommerce_custom_product_add_to_cart_text() {
return __( 'Mehr erfahren', 'woocommerce' );
}
uj5u.com熱心網友回復:
要將添加到購物車鏈接修改為存檔頁面中的單個產品鏈接,請參考以下代碼:
add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
function replacing_add_to_cart_button( $button, $product ) {
$button_text = __("Add to cart", "woocommerce");
$button = '<a href="' . $product->get_permalink() . '">' . $button_text . '</a>';
return $button;
}
要將添加到購物車鏈接修改為全域另一個重定向鏈接,下面是代碼:
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
add_action('woocommerce_single_product_summary', 'custom_single_add_to_cart', 30);
function custom_single_add_to_cart()
{
$button_text = __("Add to cart", "woocommerce");
echo '<a href="global_link_for_all_products">' . $button_text . '</a>';
}
謝謝
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/530115.html
上一篇:在移動模式下垂直對齊漢堡選單
下一篇:Paypal按鈕粘在上面
