• Resolved traveltr

    (@traveltr)


    Hi,
    I’ve read at least 20 times the same topic here :), but unfortunately it doesn’t work for our case, since we do not have theme checkout/terms.php.
    The problem is that this string is only available in Customizer Woocommerce and does not appear anywhere else to be translated (for example the privacy_policy_text from Customizer appears as a string in Polylang). We also use Loco translate and cannot make a translation of this string. Our theme authors also checked the issue and the theme does not override the woocommerce templates. So it seems the WooCommerce has decided to hide this text from translation for some reason.
    Our question is can we add the Woocommerce_terms_and_conditions_checkbox_text into Polylang strings with some line of code? Or if this is not possible, are there any solution at all?
    We have the whole site translated in 2 languages and only this string in checkout page is shown only in default language (as it is in Customizer).
    Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor jomo

    (@jonathanmoorebcsorg)

    if you look in the woocommerce file /plugins/woocommerce/templates/checkout/terms.php
    this uses:
    wc_terms_and_conditions_checkbox_text()
    which ultimately calls:

    
    apply_filters( 'woocommerce_get_terms_and_conditions_checkbox_text', get_option( 'woocommerce_checkout_terms_and_conditions_checkbox_text', sprintf( __( 'I have read and agree to the website %s', 'woocommerce' ), '[terms]' )
    

    What this means is:

    1. the default string ‘I have read and agree to the website %s’ will be translated with the woocommerce language files and customisable with loco translate
    2. if the value has been set in the customizer then it will not be translated. This could also be remediated by deleting the option for woocommerce_checkout_terms_and_conditions_checkbox_text
    3. the value can be customized using the filter woocommerce_get_terms_and_conditions_checkbox_text
    4. the whole thing can be changed by over-riding the template, which can actually be done both from a theme and from a plugin

    So as you can see there are multiple options and workarounds..

    This customiser setting is relatively recent in woocommerce and didn’t get noticed and handled by this plugin yet.
    Where custom text is provided by the admin screens (or in this case by the customizer) the normal implementation is to use pll_register_string() to register the strings and pll__() to translate them, which we would probably do on the filter.

    If you have any difficulty with this then please log an issue on:
    https://github.com/hyyan/woo-poly-integration/issues

    On the other hand, if you now see what to do you are very welcome to submit a pull request to add this to the project ??

    Plugin Contributor jomo

    (@jonathanmoorebcsorg)

    Implemented on:
    https://github.com/hyyan/woo-poly-integration/issues/446
    as a new version of:
    woo-poly-integration/src/Hyyan/WPI/Privacy.php
    https://github.com/hyyan/woo-poly-integration/blob/master/src/Hyyan/WPI/Privacy.php
    which is where these customisable strings are currently translated.

    Do note also, major shopping websites like amazon do not force you to check a checkbox before checking out. Hence one option is for the theme to override here with a more common alternative method, and translations as appropriate.

    • This reply was modified 5 years, 8 months ago by jomo.
    Thread Starter traveltr

    (@traveltr)

    Hi,
    Thank you extremely much for your detailed answer! I really highly appreciate your answer and the good will to point ways of solution.

    Please, note I’m an average WP user and perhaps have misunderstood something, because when I try to apply the above changes from fixes #446 to privacy.php without changing anything else, it really adds those strings in Polylang, but on the checkout page in the terms & conditions section I get the following error:

    Fatal error: Uncaught ArgumentCountError: Too few arguments to function Hyyan\WPI\Privacy::translatePrivacyPolicyText(), 1 passed in /home/agroport/test.grain-academy.com/wp-includes/class-wp-hook.php on line 286 and exactly 2 expected in /home/agroport/test.grain-academy.com/wp-content/plugins/woo-poly-integration/src/Hyyan/WPI/Privacy.php:61 Stack trace: #0 /home/agroport/test.grain-academy.com/wp-includes/class-wp-hook.php(286): Hyyan\WPI\Privacy->translatePrivacyPolicyText(‘\xD0\x9F\xD1\x80\xD0\xBE\xD1\x87\xD0\xB5\xD1\x82\xD0\xBE\xD1…’) #1 /home/agroport/test.grain-academy.com/wp-includes/plugin.php(208): WP_Hook->apply_filters(‘\xD0\x9F\xD1\x80\xD0\xBE\xD1\x87\xD0\xB5\xD1\x82\xD0\xBE\xD1…’, Array) #2 /home/agroport/test.grain-academy.com/wp-content/plugins/woocommerce/includes/wc-template-functions.php(793): apply_filters(‘woocommerce_get…’, ‘\xD0\x9F\xD1\x80\xD0\xBE\xD1\x87\xD0\xB5\xD1\x82\xD0\xBE\xD1…’) #3 /home/agroport/test.grain-academy.com/wp-content/plugins/woocommerce/includes/wc-template-functions.ph in /home/agroport/test.grain-academy.com/wp-content/plugins/woo-poly-integration/src/Hyyan/WPI/Privacy.php on line 61

    Thread Starter traveltr

    (@traveltr)

    I’ve noticed the ‘tranlatePrivacyPolicyText’ on row 26 in the fix perhaps has to be ‘translateTermsAndConditionsCheckboxText’? That removed the fatal error I reported in the previous reply, but now the checkbox to accept Terms&Conditions totally disappeared from Checkout page…

    Our Woocommerce checkout terms.php file looks like that and I don’t know what to change there:

    <?php
    /**
    * Checkout terms and conditions area.
    *
    * @package WooCommerce/Templates
    * @version 3.4.0
    */

    defined( ‘ABSPATH’ ) || exit;

    if ( apply_filters( ‘woocommerce_checkout_show_terms’, true ) && function_exists( ‘wc_terms_and_conditions_checkbox_enabled’ ) ) {
    do_action( ‘woocommerce_checkout_before_terms_and_conditions’ );

    ?>
    <div class=”woocommerce-terms-and-conditions-wrapper”>
    <?php
    /**
    * Terms and conditions hook used to inject content.
    *
    * @since 3.4.0.
    * @hooked wc_checkout_privacy_policy_text() Shows custom privacy policy text. Priority 20.
    * @hooked wc_terms_and_conditions_page_content() Shows t&c page content. Priority 30.
    */
    do_action( ‘woocommerce_checkout_terms_and_conditions’ );
    ?>

    <?php if ( wc_terms_and_conditions_checkbox_enabled() ) : ?>
    <p class=”form-row validate-required”>
    <label class=”woocommerce-form__label woocommerce-form__label-for-checkbox checkbox”>
    <input type=”checkbox” class=”woocommerce-form__input woocommerce-form__input-checkbox input-checkbox” name=”terms” <?php checked( apply_filters( ‘woocommerce_terms_is_checked_default’, isset( $_POST[‘terms’] ) ), true ); // WPCS: input var ok, csrf ok. ?> id=”terms” />
    <span class=”woocommerce-terms-and-conditions-checkbox-text”><?php wc_terms_and_conditions_checkbox_text(); ?></span> <span class=”required”>*</span>
    </label>
    <input type=”hidden” name=”terms-field” value=”1″ />
    </p>
    <?php endif; ?>
    </div>
    <?php

    do_action( ‘woocommerce_checkout_after_terms_and_conditions’ );
    }

    • This reply was modified 5 years, 8 months ago by traveltr.
    Plugin Contributor jomo

    (@jonathanmoorebcsorg)

    Thread Starter traveltr

    (@traveltr)

    I’m sorry too, but I get again the fatal error from above…

    Plugin Contributor jomo

    (@jonathanmoorebcsorg)

    sorry one of the changes was not checked in, the correct filter line is:
    add_filter( ‘woocommerce_get_terms_and_conditions_checkbox_text’, array( $this, ‘translateText’ ), 10, 1 );

    Thread Starter traveltr

    (@traveltr)

    Anyway I couldn’t make that work for me. After the correction there is an error message visible on the site and in the admin area, as well as the translated string does not substitute the text from Customizer on the Checkout page. The error message is:

    Warning</b>: Use of undefined constant ‘woocommerce_get_terms_and_conditions_checkbox_text’ – assumed ‘‘woocommerce_get_terms_and_conditions_checkbox_text’’ (this will throw an Error in a future version of PHP) in <b>/home/……………com/wp-content/plugins/woo-poly-integration/src/Hyyan/WPI/Privacy.php</b> on line <b>26</b><br />
    <br />
    <b>Warning</b>: Use of undefined constant ‘translateText’ – assumed ‘‘translateText’’ (this will throw an Error in a future version of PHP) in <b>/home/………..com/wp-content/plugins/woo-poly-integration/src/Hyyan/WPI/Privacy.php</b> on line <b>26</b><br />

    I think the issue is more complicated than I thought it was. Perhaps we should wait until WooCommerce decide to solve this issue, although I do not hope on that to happen soon.
    Thank you for answering me! Respect for your time!

    Plugin Contributor jomo

    (@jonathanmoorebcsorg)

    no this is just this forum corrupting the quote marks in the text, use straight quotes rather than angle quotes or the correct file from
    https://github.com/hyyan/woo-poly-integration/blob/master/src/Hyyan/WPI/Privacy.php
    which does have straight quotes…

    Thread Starter traveltr

    (@traveltr)

    You’re great! Everything works now!!! Thank you so much ?? Thank you, thank you, thank you!

    Thread Starter traveltr

    (@traveltr)

    I forgot to mark the issue as resolved! Thanks for your help once again! It’s the first time in www.remarpro.com forum (for me) to receive a prompt, competent and absolutely exact reply and solution to a problem!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘1 string in default language – woocommerce-terms-and-conditions-checkbox-text’ is closed to new replies.