Last active
October 30, 2020 11:15
-
-
Save plugin-republic/6d54ae584ad2e0d2ba99cc3e2a41a0b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Trigger an action when an add-on field is present in an order | |
* Note that you will need to change the values for $field_id and $value below | |
*/ | |
function prefix_pewc_after_create_product_extra( $add_on_id, $order, $field ) { | |
$field_id = 1234; | |
$value = '__checked__'; | |
// Check specific field ID is checked | |
if( $field['field_id'] == $field_id && $field['value'] == $value ) { | |
// Do our action here | |
prefix_send_custom_email(); | |
} | |
} | |
add_action( 'pewc_after_create_product_extra', 'prefix_pewc_after_create_product_extra', 10, 3 ); | |
/** | |
* Send an email when an add-on field is present in an order | |
* You'll need to change the values for $to, $subject and $content below | |
*/ | |
function prefix_send_custom_email() { | |
$to = 'you@youremail.com'; | |
$subject = 'Your Subject Line'; | |
$content = 'Add your content here.'; | |
ob_start(); | |
wc_get_template( 'emails/email-header.php', array( 'email_heading' => $subject ) ); | |
$email = ob_get_clean(); | |
$email .= $content; | |
wc_get_template( 'emails/email-footer.php' ); | |
$email .= ob_get_clean(); | |
wc_mail( $to, $subject, $email ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment