This thread is resolved. Here is a description of the problem and solution.
Problem:
How to translate a string that is in a PHP snippet.
Solution:
If you're experiencing this issue, we recommend wrapping the text in a WordPress gettext function so that WPML can detect it when scanning the code. Here's a step-by-step guide:
add_action( 'woocommerce_check_cart_items', 'show_free_shipping_notice' );<br /><br />function show_free_shipping_notice() {<br /> $customer = WC()->customer;<br /><br /> if ( ! $customer ) {<br /> return;<br /> }<br /><br /> $country = $customer->get_shipping_country();<br /><br /> if ( empty( $country ) ) {<br /> $country = $customer->get_billing_country();<br /> }<br /><br /> if ( $country !== 'LV' ) {<br /> return;<br /> }<br /><br /> $total = WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax() + WC()->cart->get_fee_total();<br /><br /> if ( $total < 60 ) {<br /> $remaining = 60 - $total;<br /><br /> wc_add_notice(<br /> sprintf(<br /> /* translators: %.2f is the remaining amount needed for free shipping. */<br /> __( 'Bezmaksas piegāde Latvijā pasūtījumiem no 60€. Jums trūkst vēl %.2f€.', 'wpml-custom-snippets' ),<br /> $remaining<br /> ),<br /> 'notice'<br /> );<br /> }<br />}<br />After updating the snippet, navigate to WPML → Theme and plugins localization, scan the relevant source if available, then go to WPML → String Translation and search for the text to add its translation. For more details, visit our developer documentation: https://wpml.org/documentation/support/how-to-use-gettext/
Please note that this solution might be irrelevant if it's outdated or not applicable to your case. 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 this does not resolve your issue, please open a new support ticket at WPML support forum.
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.
This topic contains 2 replies, has 1 voice.
Last updated by 1 week, 2 days ago.
Assisted by: Lucas Vidal de Andrade.