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.