Created
March 25, 2016 16:15
-
-
Save apsolut/0a4f1371fda5985492e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* | |
* Decom Custom Functions | |
* Extend and Make Future Proof | |
* Just sample file - use filter for real cases | |
* @package Decom | |
* @registration field | |
* Email notifications | |
*/ | |
/* | |
* New user | |
* send email to admin | |
*/ | |
add_action('woocommerce_created_customer', 'admin_email_on_registration', 10 , 1); | |
function admin_email_on_registration( $customer_id ) { | |
wp_new_user_notification( $customer_id ); | |
} | |
/** | |
* Code goes in functions.php or a custom plugin. | |
*/ | |
add_action( 'woocommerce_order_status_changed', 'chekaj_mail' , 1, 1); | |
function chekaj_mail($id) { | |
$customer = get_post_meta($id,'_customer_user',true); | |
$user = get_user_by( 'id', $customer ); | |
if ( in_array( 'fachhandel', $user->roles) || in_array( 'grosshandel', $user->roles) ) { | |
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' ); | |
} | |
} | |
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' ); | |
function unhook_those_pesky_emails( $email_class ) { | |
global $woocommerce; | |
$user = wp_get_current_user(); | |
if ( is_user_logged_in() && (in_array( 'fachhandel', $user->roles) || in_array( 'grosshandel', $user->roles) ) ) { | |
// Pending to | |
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) ); | |
remove_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) ); | |
remove_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) ); | |
remove_action( 'woocommerce_order_status_pending_to_cancelled_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) ); | |
remove_action( 'woocommerce_order_status_pending_to_failed_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) ); | |
remove_action( 'woocommerce_order_status_pending_to_hold_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) ); | |
// Processing to | |
// On hold to | |
// Cancelled to | |
// Refunded to | |
// Failed to | |
// Completed order emails - dont touch | |
remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) ); | |
// Refunded | |
remove_action( 'woocommerce_order_status_refunded', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) ); | |
// Note emails | |
remove_action( 'woocommerce_new_customer_note_notification', array( $email_class->emails['WC_Email_Customer_Note'], 'trigger' ) ); | |
//GermanMarket | |
remove_action('woocommerce_checkout_order_processed', array('WGM_Email', 'send_order_confirmation_mail'), 9999); | |
remove_action('woocommerce_email_after_order_table', array('WGM_Template', 'add_paymentmethod_to_mails'), 10, 2); | |
remove_filter('wgm_email_after_item_name', array('WGM_Template', 'add_product_short_desc_to_order_title_mail'), 11, 2); | |
remove_filter('woocommerce_email_settings', array('WGM_Settings', 'imprint_email_settings')); | |
remove_filter('woocommerce_email_footer', array('WGM_Email', 'email_de_footer'), 5); | |
remove_filter('woocommerce_email_footer_text', array('WGM_Email', 'get_email_de_footer'), 5); | |
remove_filter('woocommerce_email_order_meta', array('WGM_Email', 'cache_order'), 10, 1); | |
remove_action( 'wgm_order_confirmation_mail_trigger', array( $email_class->emails, 'trigger' ) ); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment