• Resolved Blue2 GmbH

    (@blue2shop)


    Hello there;
    I am searching for a solution I have never thought that it would be that hard to find.
    Hope you can help me out with your plugin!

    We have added a plugin for VAT validation. A customer is able to enter his VAT (optional) to his invoice-address.
    Now we want to get notice when a customer has entered a VAT.

    Here how it looks at admin page (last field VAT number)

    Here a screen how this field is named

    Do you have any idea if we can solve this with your plugin?

    Thanks a lot for response and advise!
    Johannes

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

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Algoritmika

    (@algoritmika)

    Hi, @blue2shop,

    Sorry for not getting back to you sooner.

    Please update the plugin to the latest v2.2.2. Then add this PHP snippet to your site:

    add_filter( 'alg_wc_custom_emails_do_send_order_email', function ( $do_send, $email, $order ) {
        if ( 1 == $email->alg_wc_ce_id ) { // for the "Custom email #1"
            return ( '' != $order->get_meta( '_billing_eu_vat_number' ) );
        }
        return $do_send;
    }, 10, 3 );

    Now custom emails will be sent only when the _billing_eu_vat_number meta is not empty.

    Please give it a try and let me know what you think.

    Thread Starter Blue2 GmbH

    (@blue2shop)

    Thanks for the feedback!
    Unfortunately that didn’t work. Plugin is up to date and I also added the snippet.
    As soon as a customer has entered something in the _billing_eu_vat_number field, nothing happens.
    Is it possible that a setting is missing in the plugin itself?

    Or maybe something needs to be adjusted for WooCommerce emails?

    Thank you for your support with this problem!

    Best regards
    Johannes

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @blue2shop,

    It looks like there are no “Triggers” set for the email. I think I misunderstood the task – where does the customer enter his VAT ID? On the checkout page, when making a new order?

    • This reply was modified 1 year, 7 months ago by Algoritmika.
    Thread Starter Blue2 GmbH

    (@blue2shop)

    Hello Algoritmika,
    the customer provides their VAT ID when entering his invoice address (/my-account/edit-address/billing/ ) .
    This should be done before ordering…

    Kind regards,
    Johannes

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @blue2shop,

    Ok, in this case, you can remove the snippet I’ve sent earlier. Instead try this:

    • Go to “WooCommerce > Settings > Custom Emails > General” and set the “Custom triggers” option to woocommerce_customer_save_address.
    • Then go to the custom email settings in “WooCommerce > Settings > Emails > Custom email” and set the “Triggers” option to woocommerce_customer_save_address.

    This should send an email every time the customer saves his address. With a few simple customizations, it should be possible to check if his EU VAT number is not empty as well.

    Please give it a try and let me know what you think.

    Thread Starter Blue2 GmbH

    (@blue2shop)

    Hello @algoritmika,
    thank you, this works. Every time a customer save their invoice address the message is sent. But I need some help to complete. The following two points still truble me:
    1. How can we solve that a message should only be sent by saving a VAT number?
    2. We use email template customizer from VillaTheme but the message will not be send by this template plugin, it is sent by normal woocommerce. I have already asked there, but do you have any idea why this is not working with your custom mail Plugin?

    Thanks a lot for giving a helping hand!

    Kind regards,
    Johannes

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @blue2shop,

    1. How can we solve that a message should only be sent by saving a VAT number?

    Try this:

    • Go to “WooCommerce > Settings > Custom Emails > General” and set the “Custom triggers” option to my_billing_eu_vat_number_set.
    • Then go to the custom email settings in “WooCommerce > Settings > Emails > Custom email” and set the “Triggers” option to my_billing_eu_vat_number_set.
    • Finally, add this PHP snippet to your site:
    add_action( 'woocommerce_after_save_address_validation', function ( $user_id, $load_address, $address, $customer ) {
    
        if ( 0 < wc_notice_count( 'error' ) ) {
            return;
        }
    
        $data_changes = $customer->get_changes();
        if ( ! empty( $data_changes['billing']['eu_vat_number'] ) ) {
            do_action( 'my_billing_eu_vat_number_set', $user_id );
        }
    
    }, 10, 4 );

    2. We use email template customizer from VillaTheme but the message will not be send by this template plugin, it is sent by normal woocommerce.

    Please try enabling the “Use actions for WC email template” checkbox in “WooCommerce > Settings > Custom Emails > General”. And make sure you’ve enabled the “WC email template > Wrap” checkbox in the custom email’s settings (in “WooCommerce > Settings > Emails > Custom email > Email Data”).

    Thread Starter Blue2 GmbH

    (@blue2shop)

    Hello Algoritmika,
    the trigger with woocommerce_customer_save_address is working.
    The trigger with my_billing_eu_vat_number_set is not working
    I have created a new Snippet with code you sent to me. However, no message is sent by saving the vat number at the billing address.
    Can it be that something with php-code is wrong? The VAT Plugin shows following field ID

    Thanks for the tip about the “Wrap” checkbox. That got me further.
    However, only the design from the Mail Customizer is used. The text content is still taken from WooCommerce > Settings > Emails.
    But since there don’t seem to be any shortcodes are working there, I need some help on how to do not only the design, but also the content using the Mail Customizer.

    Kind regards,
    Johannes

    Thread Starter Blue2 GmbH

    (@blue2shop)

    Hello Algoritmika,
    I’ve tried different combinations. The my_billing_eu_vat_number_set does not work. So I’ll leave it at woocommerce_customer_save_address. However, the message sent by this trigger does not contain any information that could be used to identify the customer. I’ve tried the shortcodes provided in your plugin but I can’t find a solution to for example display the customer name and EU VAT number in the message. Do you have a solution for the shortcodes in the message (which is sent before ordering)?

    Kind regards,
    Johannes

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @blue2shop,

    Sorry for the late reply.

    However, the message sent by this trigger does not contain any information that could be used to identify the customer.

    Update the plugin to the latest v2.2.5.

    Then add this snippet to your site:

    add_filter( 'alg_wc_custom_emails_is_user_email', function ( $is_user_email, $current_filter ) {
        return ( 'woocommerce_customer_save_address_notification' === $current_filter ? true : $is_user_email );
    }, 10, 2 );

    Now you can use the [user_prop] shortcode in your custom email. The shortcode calls the WP_User::get() function, so you can retrieve the same properties, e.g.:

    [user_prop key="nickname"]
    [user_prop key="description"]
    [user_prop key="first_name"]
    [user_prop key="last_name"]
    [user_prop key="user_login"]
    [user_prop key="user_nicename"]
    [user_prop key="user_email"]
    [user_prop key="user_url"]
    [user_prop key="display_name"]

    The my_billing_eu_vat_number_set does not work.

    I would start by adding messages to the log.

    Update our snippet to (we are adding the wc_get_logger() lines):

    add_action( 'woocommerce_after_save_address_validation', function ( $user_id, $load_address, $address, $customer ) {
    
        wc_get_logger()->info( esc_html__( 'Start.' ), array( 'source' => 'debug' ) );
    
        if ( 0 < wc_notice_count( 'error' ) ) {
            return;
        }
    
        wc_get_logger()->info( esc_html__( 'Error check passed.' ), array( 'source' => 'debug' ) );
    
        $data_changes = $customer->get_changes();
        if ( ! empty( $data_changes['billing']['eu_vat_number'] ) ) {
            wc_get_logger()->info( esc_html__( 'Doing action.' ), array( 'source' => 'debug' ) );
            do_action( 'my_billing_eu_vat_number_set', $user_id );
        }
    
        wc_get_logger()->info( esc_html__( 'End.' ), array( 'source' => 'debug' ) );
    
    }, 10, 4 );

    Then trigger the email, go to “WooCommerce > Status > Logs”, select the “debug-…” file there, and check what’s displayed. This way, we will know if our action is called, and if it is, then which point we are reaching there.

    Please give it a try and let me know what you think.

    Thread Starter Blue2 GmbH

    (@blue2shop)

    Hello Algoritmika, 
    I've tried this now. 
    
    1 - shortcodes work. However, the snippet code triggers an email to the customer and not to the admin.
    What should I change in snippet code?
    
    2-my_billing_eu_vat_number_set 
    I entered your code as a snippet. But I see no difference there. 
    If I only activate point 1 I see no difference to points 1 and 2. 
    
    I called the debugging. The following is output there:
    2023-09-04T11:09:52+00:00 INFO Start.
    2023-09-04T11:09:52+00:00 INFO Error check passed.
    2023-09-04T11:09:52+00:00 INFO End.
    2023-09-04T11:10:24+00:00 INFO Start.
    2023-09-04T11:10:24+00:00 INFO Error check passed.
    2023-09-04T11:10:24+00:00 INFO End.
    2023-09-04T11:11:10+00:00 INFO Start.
    2023-09-04T11:11:10+00:00 INFO Error check passed.
    2023-09-04T11:11:10+00:00 INFO End.
    
    Kind regards,
    Johannes
    Thread Starter Blue2 GmbH

    (@blue2shop)

    Hello Algoritmika,
    meanwhile I have found another solution for our issue.
    Anyway, I want to thank you for your support!

    Kind regards,
    Johannes

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @blue2shop,

    Happy to help ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Custom Email by special field in customers account’ is closed to new replies.