• Hi,

    I’d like to know if it’s possible to create a custom placeholder, for example {current_year}, that would work inside WooCommerce email templates—specifically in fields like the Email Footer Text.

    I’ve seen that built-in placeholders like {site_title} and {store_address} work as expected. Is there a way to register additional custom placeholders so they render properly in the final email?

    Thanks in advance for any guidance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @yarvolk ,

    Great question! While WooCommerce supports a few built-in placeholders like {site_title} and {store_address}, it doesn’t currently offer a built-in way to register custom placeholders (like {current_year}) for use in fields such as the Email Footer Text.

    That said, it is possible to achieve this with a custom code snippet. You can use a filter like woocommerce_email_footer_text to replace your custom placeholder with the desired content. For example:

    add_filter( 'woocommerce_email_footer_text', function( $footer_text ) { return str_replace( '{current_year}', date( 'Y' ), $footer_text ); } );

    This will replace {current_year} with the actual year in your email footers.

    Please note that customizations like this fall outside the scope of our support, so we recommend consulting a developer if you’re not comfortable adding code to your site.

    Thank you.

    Saif

    (@babylon1999)

    Hello @yarvolk!

    I’ve seen that built-in placeholders like {site_title} and {store_address} work as expected. Is there a way to register additional custom placeholders so they render properly in the final email?

    This should do it:

    add_filter( 'woocommerce_email_format_string', 'add_current_year_placeholder', 10, 2 );
    function add_current_year_placeholder( $string, $email ) {
    $placeholder = '{current_year}';
    $current_year = date('Y');

    return str_replace( $placeholder, $current_year, $string );
    }

    The codes inside or your child theme’s functions.php file or you can add it via a plugin like CodeSnippets. The placeholder name is {current_year} .

    Hope this helps!

    Thread Starter Yaroslav Volkov

    (@yarvolk)

    add_filter( 'woocommerce_email_footer_text', function( $footer_text ) { return str_replace( '{current_year}', date( 'Y' ), $footer_text ); } );

    Hi @mahfuzurwp
    Thank you! This filter actually worked! Topic is closed.

    Hi @yarvolk,

    You’re very welcome, I’m glad to hear that the filter worked! 🎉

    If you have a moment, we’d truly appreciate it if you could leave a review and share your experience:
    https://wordpress.org/support/plugin/woocommerce/reviews/

    Thanks again, and happy selling!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Add Custom Placeholder (e.g. {current_year}) to WooCommerce Email Footer’ is closed to new replies.