WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Disable some mail notifications in Woocommerce (2 posts)

  1. dat98cbr
    Member
    Posted 11 months ago #

    I can't see why this code doesn't work. I want to disable order status completed notifications for all cases except when there is a downloadable product. Help! :)

    [ Moderator note: code block fixed, please use the code button going forward. ]

    <?php
    
    	add_action( 'woocommerce_email', 'unhook_some_emails' );
    
    	function unhook_some_emails( $email_class) {
    		global $woocommerce, $post;
    		$order = new WC_Order( $post->ID );
    		if (!$order->has_downloadable_item()) {
    			remove_action('woocommerce_order_status_completed_notification', array(&$email_class, 'customer_completed_order'));
    			}
    	}
    
    ?>
  2. dat98cbr
    Member
    Posted 11 months ago #

    Right thought I could do it in one hook, but two are needed :)

    /** Hook for disabling sending emails during order complete, except downloadable products*/
    	add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
    	add_action('woocommerce_order_status_completed', 'send_download_notification');
    
    	function unhook_those_pesky_emails( $email_class) {
    	remove_action('woocommerce_order_status_completed_notification', array(&$email_class, 'customer_completed_order'));
    	}
    
    	function send_download_notification($order_id) {
      		global $woocommerce;
    		  $order = new WC_Order($order_id);
    		  if ($order->has_downloadable_item()){
    		  $mailer = $woocommerce->mailer();
    		  $mailer->customer_invoice( $order );
    		  }
    		}

Reply

You must log in to post.

About this Topic