• Resolved maraltto

    (@maraltto)


    Hi, I would love to use your plugin but have two quesions:

    1. I know there are several conditions to set for utomated emails. How can I enable an automatic email only for people wwho have given cosent to receive this mail? I kno I can add a cutom checkbox to the checkout and save this as meta to the database, but how can I make your plugin pick up on that?
    2. How can I add php to an email?

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello maraltto,

    I hope you are well and thank you for your message.

    Regarding the first question: This feature needs development and is not currently available in the existing version, but we will take your request into consideration to work on it in the future.
    But you can manually exclude some emails from here so that they do not receive the email if this account is not subscribed to this feature:

    Regarding the second question:

    You can add HTML code, not PHP, to the email:

    Thank you,

    Thread Starter maraltto

    (@maraltto)

    @abdhindi97 thanks, but regarding #1: I tried your fution that you provided on your own forum https://wpfactory.com/support/topic/use-order-meta-field-as-trigger/ but it is not working. And regarding #2: Only html? I need PHP because I nned to include tracking variables.

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @maraltto,

    Actually, I think both tasks are already doable with the plugin.

    Custom email recipients

    You can use the woocommerce_email_recipient_alg_wc_custom filter, for example:

    add_filter( 'woocommerce_email_recipient_alg_wc_custom', function ( $recipient, $_object, $email ) {
        $users  = get_users( array( 'role__in' => array( 'administrator', 'shop_manager' ) ) );
        $emails = implode( ',', array_unique( wp_list_pluck( $users, 'user_email' ) ) );
        return $emails;
    }, 10, 3 );

    This example will set “Custom email?#1” recipients to all users with?administrator?or?shop_manager?user roles. To set it for a different custom email (e.g., “Custom email?#2”), you need to replace?woocommerce_email_recipient_alg_wc_custom?with?woocommerce_email_recipient_alg_wc_custom_2, etc.

    PHP in emails

    One option would be to use the alg_wc_custom_emails_content filter, for example:

    add_filter( 'alg_wc_custom_emails_content', function ( $content, $email, $order, $user, $product ) {
        if ( 1 == $email->alg_wc_ce_id ) { // for the "Custom email #1"
            return 'Your custom content';
        }
        return $content;
    }, 10, 5 );

    Another option – modify the email template directly by copying it from custom-emails-for-woocommerce/templates/emails/alg-wc-custom-email.php to yourtheme/woocommerce/emails/alg-wc-custom-email.php.

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

    Thread Starter maraltto

    (@maraltto)

    Thanks, but regarding the first issue, this is not a soluton The users who should get an email don’ have arole like admin, customer etc. They are defined by the order custom meta field that I am adding to the checkout. If the checkbox is checked during the checkout, the meta field with the key “consent” will be 1, and if they don’t check the checkbox, it will be 0. So depending on if the value is 1 or 0, the emails should get sent.

    Plugin Author Algoritmika

    (@algoritmika)

    @maraltto,

    Ok. In this case, I think what we need is the alg_wc_custom_emails_do_send_order_email filter:

    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 ( 1 == $order->get_meta( 'consent' ) );
        }
        return $do_send;
    }, 10, 3 );
    Plugin Author Algoritmika

    (@algoritmika)

    @maraltto,

    P.S. About PHP in emails – another solution would be to create your own shortcodes, and then use them in the “Email content” option (in “WooCommerce > Settings > Emails > Custom email #X > Email Data”).

    For example, to create the [my_order_country] shortcode:

    add_shortcode( 'my_order_country', function ( $atts ) {
        if ( function_exists( 'alg_wc_custom_emails' ) && isset( alg_wc_custom_emails()->core->shortcodes->email ) ) {
            $email = alg_wc_custom_emails()->core->shortcodes->email;
            if ( 1 == $email->alg_wc_ce_id ) { // for the "Custom email #1"
                $order = alg_wc_custom_emails()->core->shortcodes->order;
                return $order->get_billing_country();
            }
        }
    } );

    This way, you will be modifying only the inner part of the email content, i.e., without the WooCommerce header and footer (unlike the alg_wc_custom_emails_content filter I mentioned earlier).

    Hi there,

    I hope you are well and safe.

    We haven’t received any reply regarding the issue. So, we are going to mark the ticket as “Resolved”. But if you have any questions, then please let us know.

    Kind regards,
    Moshtafizur

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Consent/PHP’ is closed to new replies.