實用的 WordPress ICP 備案許可管理器

WooCommerce 如何更改 「添加到購物車」 按鈕文本?

您是否正在尋找一種方法來更改 WooCommerce 中默認的 「添加到購物車」 按鈕文本?此代碼片段可讓您將文本更改為 「立即購買」 、 「添加到購物」 、 「立即預訂」 或您喜歡的任何自定義文本。

更改默認添加到購物車文本的步驟

  1. 打開 WordPress 管理面板,轉到外觀 > 主題編輯器 
  2. 打開 functions.php 子主題功能文件
  3. 在 function.php 文件底部添加以下代碼
  4. 保存更改並檢查您的網站。現在應該顯示添加到購物車按鈕中的自定義文本。
 // To change add to cart text on single product page add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' );  function woocommerce_custom_single_add_to_cart_text() {     return __( 'Buy Now', 'woocommerce' );  }  // To change add to cart text on product archives(Collection) page add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );   function woocommerce_custom_product_add_to_cart_text() {     return __( 'Buy Now', 'woocommerce' ); }

修改 Buy Now 為您需要的文字內容就行。

文章沒看懂?代碼不會用?需要幫助您可以

詩語 的頭像