How to change Add to basket text on the storefront theme - woocommerce

I cannot seem to replace the text inside the Add to basket buttons on the single product pages, im using a child theme with the storefront theme for WooCommerce.
Here's what i've tried:
add_filter('woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_add_to_cart_text');
function woocommerce_custom_add_to_cart_text() {
return __('Add to cart', 'woocommerce');
}
How the button appears on the DOM:
<button type="submit" name="add-to-cart" value="117" class="single_add_to_cart_button button alt">Add to basket</button>

I do think the issue is theme-related as your code does work when I try it on a test site, though I don't have Storefront set as the theme.
You could try a string replace:
add_filter( 'gettext', 'change_woocommerce_strings', 999, 3 );
function change_woocommerce_strings( $changed, $text, $domain ) {
$changed = str_ireplace( 'Add to basket', 'Add to cart', $changed );
return $changed;
}

Related

Need to Change Sale Badge Text in WooCommerce

The following works for the Product page but it does not work for the Shop page.
<?php
add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3);
function woocommerce_custom_sale_text($text, $post, $_product)
{
return '<span class="onsale">PUT YOUR TEXT</span>';
}
Please suggest modifications.
Thanks!
Use This
add_filter( 'woocommerce_sale_flash', 'wooc_custom_replace_sale_text' );
function wooc_custom_replace_sale_text( $html ) {
return str_replace( __( 'Sale!', 'woocommerce' ), __( 'Your Text', 'woocommerce' ), $html );
}
I tried your code and it works perfectly for the shop page as well. You may try increasing the priority or it can be a conflict with some other plugin or theme.
You may also check the following file to confirm it has applied the woocommerce_sale_flash filter
woocommerce\templates\loop\sale-flash.php

Change woocommerce cart link in menu [duplicate]

On Woocommerce, how can we change the URLs on "View cart" and "Checkout" links on the drop down menu that show up on hover over the shopping cart icon on the the home page?
I have the "cart" and "checkout" pages setup but they are not linked to these.
I can view these pages directly with urls. http://mysite/cart and http://mysite/checkout
It seems that there is a problem somewhere with your theme (or in a plugin), as the minicart button links always point to the right cart and checkout pages.
The minicart buttons are hooked in woocommerce_widget_shopping_cart_buttons action hook (in the cart/mini-cart.php WooCommerce template). You will find the details HERE on includes/wc-template-hooks.php core file. It calls 2 functions that are displaying the buttons.
First you should try to refresh WordPress Permalinks, going on WP Settings > Permalinks:
Just at the end of the page click on "save". Empty your cart, and try it again to see if it changes something.
In the code below I remove first the original buttons and I replace them by the same ones where the links are customized. For each you can change the link to feet your needs (I have added in the links ?id=1 (at the end) just for testing purpose, to check changes):
add_action( 'woocommerce_widget_shopping_cart_buttons', function(){
// Removing Buttons
remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 );
remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );
// Adding customized Buttons
add_action( 'woocommerce_widget_shopping_cart_buttons', 'custom_widget_shopping_cart_button_view_cart', 10 );
add_action( 'woocommerce_widget_shopping_cart_buttons', 'custom_widget_shopping_cart_proceed_to_checkout', 20 );
}, 1 );
// Custom cart button
function custom_widget_shopping_cart_button_view_cart() {
$original_link = wc_get_cart_url();
$custom_link = home_url( '/cart/?id=1' ); // HERE replacing cart link
echo '' . esc_html__( 'View cart', 'woocommerce' ) . '';
}
// Custom Checkout button
function custom_widget_shopping_cart_proceed_to_checkout() {
$original_link = wc_get_checkout_url();
$custom_link = home_url( '/checkout/?id=1' ); // HERE replacing checkout link
echo '' . esc_html__( 'Checkout', 'woocommerce' ) . '';
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
All code is tested on Woocommerce 3+ and works.

Can't change 'cart' to be 'basket' in woocommerce

I've tried adding this code:
add_filter( 'woocommerce_product_single_add_to_cart_text',
'woo_custom_cart_button_text' );
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' );
function woo_custom_cart_button_text() {
return __( 'Add to basket', 'woocommerce' );
}
To functions PHP, but as you can still see by this page, only some of the text has changed to 'basket'
Page with 'cart'
However, on the other page it seems to have worked:
Working page
Why won't it change on the other page (the text), but on the single product page?
Add another line to your code -
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text',999 );
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_woocommerce_product_add_to_cart_text' );
function custom_woocommerce_product_add_to_cart_text() {
return __( 'Read more', 'woocommerce' );
}
Try this filter

Product page details tabs to lightbox

in my woocomere product page there is tabs of a product to display different information (description, etc). But i wish to be able to in a specific tab turn in a ligthbox popup that shows text or a image. Is there any plugin available in wordpress for it?
Please try below code in function.php to show tab content in light box. Might be you will have to customize more but basic structure i am sharing with you.
add_action( 'woocommerce_product_write_panel_tabs','outputTabTitle');
add_action( 'woocommerce_product_write_panels','outputTabEditContent');
add_filter( 'woocommerce_product_tabs','productTab');
function outputTabTitle ()
{
?>
<li class="custom_tab">
Additional Information
</li>
<?php
}
function outputTabEditContent ()
{
global $woocommerce, $post;
echo '<div id="custom-tab" class="panel woocommerce_options_panel">';
/************Please put you lightbox text and image here.
echo '</div>';
}
function productTab ( $tabs )
{
$tabs['custom-tab'] = array(
'title' => __( 'Additional Information', 'woocommerce' ),
'priority' => 50,
'callback' => 'outputTabEditContent'
);
return $tabs;
}

How do I change the add to cart text on the cart page only?

I'm trying to change the "add to cart" button text to 'Complete Sale' when on the shopping cart page, be "subscribe now" on product id 4968, and be 'Book' everywhere else.
Here is my code in the functions.php file:
function woo_custom_cart_button_text() {
if (is_single('Product1')) {
return __( 'Subscribe Now', 'woocommerce' );
} else {
return __( 'Book', 'woocommerce' );
}
}
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
Try to change is_single to is_page(). And put slug or id of the page inside the is_page().

Resources