Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client had custom buttons for WooCommerce's Minicart widget and was unable to find an option to translate the button's text using WPML string translations. The code snippet provided was included in the child theme's functions.php file and worked for the primary language, but the translations were not appearing in WPML.
Solution:
If you're experiencing issues with translating custom button texts in WooCommerce's Minicart widget, first ensure that your strings are properly wrapped for translation. The client's buttons were already using the

esc_html__()

function, which is correct. We recommend scanning your child theme again in WPML to find the strings. Here's a step-by-step guide:
1. Go to WPML > Theme and plugins localization.
2. Make sure that the 'Translate by WPML.' option is selected.
3. Click on the 'Scan the theme for strings' button.
4. Once the scan is complete, go to WPML > String Translation. You should now see the strings and be able to translate them.
Additionally, review our documentation on enabling text translation for themes not compatible with WPML: https://wpml.org/documentation/support/enabling-text-translation-for-themes-not-compatible-with-wpml/
Please note that the solution provided might be irrelevant if it's outdated or not applicable to your case. If the issue persists, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket with us.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by jiriP-9 11 months, 4 weeks ago.

Assisted by: Bobby.

Author Posts
May 1, 2024 at 4:11 pm #15584468

jiriP-9

I have custom buttons for Woocommerce's Minicart widget done with this code snippet. But I can't find any option to translate the button's text in the WPML string translations. I've tried refresh the localization files with no success. Can you provide me with some guidance please?

<?php

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 );

function my_woocommerce_widget_shopping_cart_button_view_cart() {
echo '' . esc_html__( 'Zobrazit košík', 'woocommerce' ) . '';
}
function my_woocommerce_widget_shopping_cart_proceed_to_checkout() {
echo '' . esc_html__( 'K objednávce', 'woocommerce' ) . '';
}
add_action( 'woocommerce_widget_shopping_cart_buttons', 'my_woocommerce_widget_shopping_cart_button_view_cart', 10 );
add_action( 'woocommerce_widget_shopping_cart_buttons', 'my_woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );

May 1, 2024 at 6:54 pm #15584801

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

Custom work is outside the scope of our support, however, I'll do my best to guide you in the right direction.

Also, please review the following documentation on how to use the gettext function to properly wrap strings for translation with WPML.

https://wpml.org/documentation/support/enabling-text-translation-for-themes-not-compatible-with-wpml/

The button strings in your PHP code are already wrapped with the esc_html__() function for localization.

where do you add this PHP code? Is it added to your theme's functions.php file?

May 2, 2024 at 3:14 pm #15588257

jiriP-9

Hello,

I've got this snippet in a file in my child theme. It is included into child's functions.php and it works for the primary language. But the translations don't work or show up in WPML.

EDIT: I've got it. Now I scanned the child theme again in WPML and it showed up. So problem solved. Thanks