Title: Consent/PHP
Last modified: December 12, 2023

---

# Consent/PHP

 *  Resolved [maraltto](https://wordpress.org/support/users/maraltto/)
 * (@maraltto)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/consent-php/)
 * 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)

 *  [Abd Hindi](https://wordpress.org/support/users/abdhindi97/)
 * (@abdhindi97)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/consent-php/#post-17283327)
 * 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:
 * ![](https://i0.wp.com/i.postimg.cc/BQjNnKFp/2023-12-17-07h49-20.png?ssl=1)
 * Regarding the second question:
 * You can add HTML code, not PHP, to the email:
 * ![](https://i0.wp.com/i.postimg.cc/zXHSr1mP/2023-12-17-07h55-37.png?ssl=1)
 * Thank you,
 *  Thread Starter [maraltto](https://wordpress.org/support/users/maraltto/)
 * (@maraltto)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/consent-php/#post-17283337)
 * [@abdhindi97](https://wordpress.org/support/users/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/](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](https://wordpress.org/support/users/algoritmika/)
 * (@algoritmika)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/consent-php/#post-17294400)
 * Hi, [@maraltto](https://wordpress.org/support/users/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:
 *     ```wp-block-code
       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:
 *     ```wp-block-code
       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](https://wordpress.org/support/users/maraltto/)
 * (@maraltto)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/consent-php/#post-17294506)
 * 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](https://wordpress.org/support/users/algoritmika/)
 * (@algoritmika)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/consent-php/#post-17294644)
 * [@maraltto](https://wordpress.org/support/users/maraltto/),
 * Ok. In this case, I think what we need is the `alg_wc_custom_emails_do_send_order_email`
   filter:
 *     ```wp-block-code
       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](https://wordpress.org/support/users/algoritmika/)
 * (@algoritmika)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/consent-php/#post-17295204)
 * [@maraltto](https://wordpress.org/support/users/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:
 *     ```wp-block-code
       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).
 *  [Moshtafizur](https://wordpress.org/support/users/moshtafizur01/)
 * (@moshtafizur01)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/consent-php/#post-17811902)
 * 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.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-emails-for-woocommerce_cef1f4.
   svg)
 * [Additional Custom Emails & Recipients for WooCommerce](https://wordpress.org/plugins/custom-emails-for-woocommerce/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-emails-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-emails-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-emails-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-emails-for-woocommerce/reviews/)

 * 7 replies
 * 4 participants
 * Last reply from: [Moshtafizur](https://wordpress.org/support/users/moshtafizur01/)
 * Last activity: [1 year, 11 months ago](https://wordpress.org/support/topic/consent-php/#post-17811902)
 * Status: resolved