• Resolved ticoocit

    (@ticoocit)


    Hi there,
    hope you can help me on this.
    I need 2 custom fields on my emails. Billing_email and order_id.
    The order_id I’m already getting through {order_id} on the customized emails of WooCommerce. But if I add {billing_email}, there is no change, just this string.
    Do you know how I can get {billing_email} on the email sent to customer about order completed?
    Thank you in advance for any kind of help.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Claudio Sanches

    (@claudiosanches)

    Hello @ticoocit,

    It’s possible to use any placeholder that you want, but you need to some coding skills and to use the woocommerce_email_format_string filter, here an example of how to achieve what you want:

    add_filter( 'woocommerce_email_format_string', function( $string, $email ) {
    	if ( ! empty( $email->object ) && is_callable( array( $email->object, 'get_billing_email' ) ) ) {
    		return str_replace( '{billing_email}', $email->object->get_billing_email(), $string );
    	}
    
    	return $string;
    }, 10, 2 );
    

    I hope it helps you.

    Thread Starter ticoocit

    (@ticoocit)

    Hi @claudiosanches,
    first of all, let me thank you for helping me on this.

    As you passed me the code, I don’t need skills on coding, right? ehehe ??

    [BEFORE EDIT]
    What I’m trying to understand is where I can paste that code? On the customer-completed-order.php, on editing woocoomerce?

    [EDIT]
    I got it! I paste it on class-wc-emails.php and it’s already functioning!!!!

    Thank you so much!!!That made my day!

    • This reply was modified 4 years ago by ticoocit.
    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    @ticoocit there’s many ways to insert a code like that on your installation, but you shouldn’t edit existing plugins, since those changes will get lost in case you update the plugin, so here a better solution in using a plugin that allows you enter any snippet like this one into your WordPress installation: https://docs.woocommerce.com/document/customizing-woocommerce-best-practices/

    But you could also create a simple plugin by just creating a file PHP file like wp-content/plugins/my-plugin.php.

    Inside my-plugin.php you can enter:

    /*
     * Plugin name: Custom email placeholders for WooCommerce
     */
    
    add_filter( 'woocommerce_email_format_string', function( $string, $email ) {
    	if ( ! empty( $email->object ) && is_callable( array( $email->object, 'get_billing_email' ) ) ) {
    		return str_replace( '{billing_email}', $email->object->get_billing_email(), $string );
    	}
    
    	return $string;
    }, 10, 2 );
    

    Because the Plugin name comment now makes file is a plugin and you can enable it on your WordPress installation.

    I hope it helps.

    Thread Starter ticoocit

    (@ticoocit)

    I’ve tried what you told me, I activated the plugin, but the dashboard and the site doesn’t react very well as you can see:

    https://ibb.co/BnvyTXL

    https://ibb.co/9yWG5mg

    https://ibb.co/2MHk8pM

    Do you think it is better to edit with the Jetpack?

    Thank you so much for helping me!

    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    @ticoocit sorry! I forget to say that you need to start that plugin file with <?php, so it will get read as PHP instead of just HTML like is happening now. I’m very sorry!

    Thread Starter ticoocit

    (@ticoocit)

    @claudiosanches is totally fine! I should have noticed that was missing that part. ??

    So now it’s working perfectly. You mentioned about the “Plugin Name”, that what is stated on comment block is what the plugin is called on the plugins dashboard, is that right?

    Thank you so much! You see..
    1. You helped with my question
    2. You created a small plugin for me
    3. AND YOU THOUGHT ME HOW TO MAKE MY OWN PLUGIN WORKING!

    That is a lot more what I expected to learn!

    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    You mentioned about the “Plugin Name”, that what is stated on comment block is what the plugin is called on the plugins dashboard, is that right?

    Yes, It’s correct, if you can edit and enter any name. In case you want to learn more you can find the documentation here: https://developer.www.ads-software.com/plugins/plugin-basics/header-requirements/

    Glad to help ??

    Thread Starter ticoocit

    (@ticoocit)

    Thanks you!! I’ll give it a check, absolutely! ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Have billing_email on the email sent to customer’ is closed to new replies.