wxa1
Forum Replies Created
-
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 1 year, 9 months ago by wxa1.
Hello! It is possible with a custom shortcode. Here is an example:
add_filter('mailpoet_newsletter_shortcode', 'mailpoet_custom_shortcode', 10, 6);
function mailpoet_custom_shortcode($shortcode, $newsletter, $subscriber, $queue, $newsletter_body, $arguments) {
// always return the shortcode if it doesn't match your own!
if ($shortcode !== '[custom:czech_name]') return $shortcode;
$name = $subscriber->getFirstName();
return $name ? apply_czech_name_ending($name) : 'abonent';
}The implementation of the
apply_czech_name_ending()function which will translate Peter to Petře etc. is left to you, obviously. There are probably libraries for that on the web. Add the resulting code to yourfunctions.php. After that you’ll be able to add the[custom:czech_name]shortcode to your newsletter, and Czech name endings will appear in the content.Please see the custom shortcode reference for more detail: https://kb.mailpoet.com/article/160-create-a-custom-shortcode