最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Make modification of add_to_cart button specific to single page

programmeradmin0浏览0评论

I am using WooCommerce for the eCommerce part of my WordPress site.

When using the add_to_cart button I want it to say "read more" on a specific webpage only.

So far I have found the code to change the button text:

add_filter('woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text');

function woo_custom_cart_button_text() {
return__('Read More','woocommerce'); }

The question is, how do I make this apply to the appearance of the add_to_cart button on a single page of my website? The page is not a shop page. It is a normal webpage where is have the description of products and the associated treatment. The button is there to take them to the product page.

I am using WooCommerce for the eCommerce part of my WordPress site.

When using the add_to_cart button I want it to say "read more" on a specific webpage only.

So far I have found the code to change the button text:

add_filter('woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text');

function woo_custom_cart_button_text() {
return__('Read More','woocommerce'); }

The question is, how do I make this apply to the appearance of the add_to_cart button on a single page of my website? The page is not a shop page. It is a normal webpage where is have the description of products and the associated treatment. The button is there to take them to the product page.

Share Improve this question edited Jun 4, 2020 at 23:38 stealthyninja 1,1301 gold badge15 silver badges21 bronze badges asked Jun 4, 2020 at 12:46 Jack Borg-CardonaJack Borg-Cardona 111 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 0

Why not add a regular button with link to the product page, as in <a href..><button></button></a>?

You use two different text for product listing page and product details page.

  1. Open Wordpress admin panel, go to Appearance > Theme Editor Open functions.php theme file
  2. Add the following code at the bottom of function.php file
  3. Save the changes and check your website. The custom text in add to cart button should show up now.
 // 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' );
}
发布评论

评论列表(0)

  1. 暂无评论