I want to update the default 'Add To Cart' text to be more suitable for my website. I have created a child theme using Astra, installed it, and then on the Theme Editor in WordPress I added a new function to my functions.php file that should have done the trick
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );
function woocommerce_custom_product_add_to_cart_text() {
return __( 'Check it out', 'woocommerce' );
}
From all the examples online it should be this easy. I just read from another post that this may be deprecated now? Should this still work, anything else I can check? I want this to be the button text globally on all products but each product still shows 'Add To Cart'. I saved and then reloaded my website but do not see any changes
add_filter( 'woocommerce_product_add_to_cart_text', 'mujuonly_add_to_cart', 10, 2 );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'mujuonly_add_to_cart', 10, 2 );
function mujuonly_add_to_cart( $text, $class ) {
return __( 'Check it out', 'woocommerce' );
}
Tested OK with WC 4.9
Related
I am trying to change the Add To Cart text on the product page button to Buy Now
I've tried using the function that's being posted everywhere to solve the issue but somehow that doesn't seem to do the trick, also using a WordPress plugin is not changing the text.
So far I've found the following function
// 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' );
}
Adding that to my Code Inserter creates an error and breaks the website.
I think that Divi is overruling the function from somewhere. Any tips or ideas?
I have a problem with translating the Add to cart button on woocommerce.
My website is: http://test.mk/OPA
The website is in albanian and english. First language is English.
I have installed Polylang Pro plugin and also tried with Loco translate.
I have changed the "name" of the Add to cart button with this code in functions.php:
//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 __( 'Order 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 __( 'Order Now', 'woocommerce' );
}
So, what I really need to translate is Order Now.
I added the string using this code:
add_action('init', function() {
pll_register_string('woocommerce_product_add_to_cart_text', 'Order Now', 'WooCommerce');
});
It is in strings in the polylang plugin, but it is not translating.
Does someone know how to help me to translate the button & the Cart wiget that is also in the website?
Thank you in advance.
You can try with this function:
// change the text of the add to cart button according to the language
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text', 99, 1 );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text', 99, 1 );
function woocommerce_custom_single_add_to_cart_text( $text ) {
// returns the current language "Polylang"
switch ( pll_current_language() ) {
case 'en':
return __( 'Order Now', 'woocommerce' );
case 'sq':
return __( 'Porosit tani', 'woocommerce' );
}
return $text;
}
Change the text of the "Add to cart" button according to the current language of the site.
This function should work but I believe you should search the Polylang plugin documentation to correctly translate the string.
The code must be inserted in the functions.php file of the active theme.
I have a question about changing text of place_order.
Check out page will reload form by update_checkout Event, So the place_order text will change back to original text ‘proceed to Paypal’.
I've tried to use Jquery and function hook to change text but still change back.
function woo_custom_order_button_text() {
return __( 'Your new button text here', 'woocommerce' );
}
How can I change the text of #place_order by not disable the update_checkout Event?
To change the place order button text when Paypal is the chosen payment gateway use the following:
add_filter( 'gettext', 'change_checkout_paypal_pay_button_text', 10, 3 );
function change_checkout_paypal_pay_button_text( $translated_text, $text, $domain ) {
if( 'Proceed to PayPal' === $text ) {
$translated_text = __('Your custom text', $domain); // <== Here the replacement txt
}
return $translated_text;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Now to change the place order text for others payment gateways, you will use in addition the following:
add_filter( 'woocommerce_order_button_text', 'custom_checkout_place_order_text' );
function custom_checkout_place_order_text( $button_text ) {
return __( 'Your custom text here', 'woocommerce' ); // <== custom text Here
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
I need to move the Product Meta content from under the "Add to Cart" button to the "Additional Information" Tab, I want it to display similar to the attribute as the client wants to move this information to Additional Information Tab.
For eg - http://yellowbee.online/product/yellow-bee-aqua-bug-led-clogs/
I need to move the "SKU", "Categories" and "Tags" to the tab which says "Additional Information"
Website is made using xStore Theme on Wordpress & Woocommerce, I have tried reading a lot on how to achieve this but all attempts have failed.
I have tried adding the following code to the functions.php in the child theme. No Luck.
function additional_product_tabs_metabox()
{
add_meta_box(
'add_product_metabox_additional_tabs',
__( 'Additional product Tabs', 'woocommerce' ),
'additional_product_tabs_metabox_content',
'product',
'normal',
'high'
);
}
I am hoping that someone has a solution on the right code to to get this hook and then to display it in the additional information tab.
This can be done with the following:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_product_additional_information', 'woocommerce_template_single_meta', 10 );
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
This will work if the related hooks are not yet customized by the theme or a plugin.
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
$tabs['delivery_information'] = array(
'title' => __( 'Additional information', 'woocommerce' ),
'priority' => 16,
'callback' => 'product_additional_info_tab'
);
return $tabs;
}
function product_additional_info_tab() {
$info = get_post_meta(get_the_ID(),
'additional_product_tabs_metabox_content', true);
echo $info;
}
I am using Woocommerce V2.1.2 in Latest version of wordpress. I have googled, they have given a solution to change in frontend. But I need to change from backend.
Kindly suggest any idea's to fix the above issue.
This will change Add to cart button text in woocommerce...
I am not sure but this will help you in < 2.1 versions...I don't know about 2.1+
Add this code into your theme's functions.php file.
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' );
//For Single Product Page.
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
//For Archives Product Page.
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text' );
function woo_custom_cart_button_text()
{
return __( 'My Button Text', 'woocommerce' );
}
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' );
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text' );
add_filter('woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text');
function woo_custom_cart_button_text() {
return __( 'Buy Now', 'woocommerce' );
}