• Resolved jwbdv

    (@jwbdv)


    hi ??
    i want to translate the woocommerce checkout checkox into mulit languages.
    In the pi backend i can only add one language.
    But i found a filter here: mailpoet\lib\WooCommerce\Subscription.php line 103

    i tried to use it, but it didn′t work:
    add_filter(‘mailpoet_woocommerce_checkout_optin_template’, function($template, $inputName, $checked, $labelString) {
    if ( ICL_LANGUAGE_CODE == ‘fr’ ) {
    $labelString = ‘Je souhaite recevoir des e-mails exclusifs contenant des offres spéciales et des informations sur les produits.’;
    }
    $template = wp_kses(
    $this->getSubscriptionField($inputName, $checked, $labelString),
    $this->allowedHtml
    );
    return $template;
    }, 10, 4);

    Can you help, or do you have an example for this?

    Thx a lot !

Viewing 1 replies (of 1 total)
  • Plugin Author wxa1

    (@wxa1)

    Hi @jwbdv !

    The code you wrote is intended for the old, non-block-based WooCommerce checkout. The working example for it would be the following one:

    add_filter('mailpoet_woocommerce_checkout_optin_template', function($template, $inputName, $checked, $labelString) {
    if ( ICL_LANGUAGE_CODE == 'fr' ) {
    $labelString = 'Je souhaite recevoir des e-mails exclusifs contenant des offres spéciales et des informations sur les produits.';
    $template = preg_replace('/<span>(*.?)</span>/i', '<span>' . $labelString . '</span>', $template);
    }
    return $template;
    }, 10, 4);

    If you are using the new block-based WooCommerce checkout, the above code won’t work, you’ll need a different approach:

    add_action('woocommerce_blocks_checkout_block_registration', function ($integration_registry) {
    $labelString = '';
    if (ICL_LANGUAGE_CODE == 'fr') {
    $labelString = 'Je souhaite recevoir des e-mails exclusifs contenant des offres spéciales et des informations sur les produits.';
    }
    if (empty($labelString)) {
    return false;
    }
    $optinBlockClassName = '\MailPoet\PostEditorBlocks\MarketingOptinBlock';
    $wpFunctionsClassName = '\MailPoet\WP\Functions';
    if (!class_exists($optinBlockClassName) || !class_exists($wpFunctionsClassName)) {
    return false;
    }
    foreach ( $integration_registry->get_all_registered() as $integration_name => $registered_integration ) {
    if ($integration_name === 'mailpoet') {
    $optinBlockOptions = $registered_integration->get_script_data();
    $optinBlock = new $optinBlockClassName(
    array_merge($optinBlockOptions, ['defaultText' => $labelString]),
    new $wpFunctionsClassName
    );
    $integration_registry->unregister('mailpoet');
    $integration_registry->register($optinBlock);
    return;
    }
    }
    },
    20 // Run after MailPoet MarketingOptinBlock registration
    );

    I hope the provided snippets were helpful, let us know if you have more questions.

    • This reply was modified 7 months, 2 weeks ago by wxa1.
Viewing 1 replies (of 1 total)
  • The topic ‘translate checkbox – mulitlang wpml’ is closed to new replies.