Reputation: 871
How can I change the "Add to cart" button text/link in woocommerce (v2.4)?
I tried to add this code to my functions.php, but it doesn´t seem to work:
add_action('woocommerce_after_shop_loop_item','replace_add_to_cart');
function replace_add_to_cart() {
global $product;
$link = $product->get_permalink();
$text = _( 'Learn More', 'woocommerce' );
echo '<a href="'.$link.'" class="button addtocartbutton">Learn more</a>';
}
Upvotes: 2
Views: 11239
Reputation: 2192
To change you add to cart button text paste this code in your theme functions.php
add_filter( 'add_to_cart_text', 'woo_custom_single_add_to_cart_text' );
// < 2.1
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_single_add_to_cart_text' ); // 2.1 +
function woo_custom_single_add_to_cart_text() {
return __( 'Learn More', 'woocommerce' );
}
Upvotes: 0
Reputation: 322
It was asked for WC 2.4. If you need it for newer versions you should use
add_filter( 'woocommerce_product_add_to_cart_text',function(){
return __( 'Learn more','your-textdomain' );
} );
Tested with WooCOmmerce 5.6
Upvotes: 1
Reputation: 1
This line of code needs to be added to the functions.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');
This is for removing the product from product listing page.
@Lorenz I think you should go through this https://www.wpblog.com/add-to-cart-button-in-woocommerce-store/
Upvotes: 0
Reputation: 7211
You have written correct code, but before using woocommerce_after_shop_loop_item
hook, you have to remove "add to cart" button using same hook as shown below.
Step 1 - Remove "add to cart" button from shop
function remove_loop_button(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_filter( 'woocommerce_is_purchasable', false );
}
add_action('init','remove_loop_button');
Step 2 -Add new button that links to product page for each product
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">Learn more</a>');
}
Upvotes: 0