• Resolved terpentin

    (@terpentin)


    Hi,
    I have a self coded theme, there I added a feature which gives me the possibility to send a custom email when I select it in the dropdown at the Order/Post page and hit Save.
    Since WooCommerce 6.0.0 the emails doesn’t get triggered anymore.
    I set up a brand-new instance of WordPress & WooCommerce 6.0.0 & WP SMTP Simple and uploaded my theme and added a test product and made a test order. All transactional emails got sent. Then I tried to send my custom email, and it doesn’t work. Also, no errors in the log.
    Then I downloaded Version 5.9.0 replaced the files and…. tadaaa it worked.

    
    //add email classes
    function add_rechnung_order_woocommerce_email( $email_classes ) {
    	$email_classes['WC_Rechnung_Order_Email'] = include( 'class-wc-rechnung-order-email.php' );
    	$email_classes['WC_Mahnung_Email'] = include( 'class-wc-mahnung-email.php' );
        return $email_classes;
    }
    add_filter( 'woocommerce_email_classes', 'add_rechnung_order_woocommerce_email');
    
    //Add Select to Dropdown
    function mahnung_add_order_meta_box_action( $actions ) {
    	global $theorder;
    	if ($theorder->get_payment_method() == 'invoice') {
            $actions['mahnung'] = "Mahnung senden";
    		$actions['b2brechnungsemail'] = "B2B Rechnungsemail";
        }
    	return $actions;
    }
    add_action( 'woocommerce_order_actions', 'mahnung_add_order_meta_box_action' );
    
    //Trigger mahnung
    function mahnung_woocommerce_email_actions( $actions ){
    	$actions[] = 'woocommerce_order_action_mahnung';
    	return $actions;
    }
    add_filter( 'woocommerce_email_actions', 'mahnung_woocommerce_email_actions' );
    
    // in the Constructor there is the following trigger
    add_action( 'woocommerce_order_action_mahnung', array( $this, 'trigger' ), 10, 2 );
    
    • This topic was modified 4 years, 4 months ago by terpentin.
    • This topic was modified 4 years, 4 months ago by terpentin.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter terpentin

    (@terpentin)

    No one here who has an idea? Or have I expressed myself incomprehensibly?

    Hi @terpentin

    I understand that since upgrading to WooCommerce 6.0.0 a particular custom email is not getting sent though all transactional emails are getting sent.

    You’d want to check if that custom email is being correctly generated or not, by installing a plugin like WP Mail Logging.

    Let us know how it goes.

    Hi,

    the same problem on WooCommerce 6.0.0
    I look like the “trigger” isn’t trigger.

    function kia_wc_add_order_meta_box_action( $actions ) {
    	global $theorder;
    	
    	// ADD "Email class details" CUSTOM ACTION
    	$actions['kia_email_class_detail_action'] = __( 'Custom email send', 'kia_class' );
    
    function kia_custom_woocommerce_email_actions( $actions ){
    	$actions[] = 'woocommerce_order_action_kia_email_class_detail_action';
    	return $actions;
    }
    add_filter( 'woocommerce_email_actions', 'kia_custom_woocommerce_email_actions' );
    
    add_action( 'woocommerce_order_action_kia_email_class_detail_action', array( $this, 'trigger' ) );
    	return $actions;
    }
    • This reply was modified 4 years, 4 months ago by cavalihno.
    • This reply was modified 4 years, 4 months ago by cavalihno.
    • This reply was modified 4 years, 4 months ago by cavalihno.
    Thread Starter terpentin

    (@terpentin)

    Hi @margaretwporg
    thanks for your help.
    I installed the plugin you mentioned, but it only shows me, what I already know.
    Transactional and the common emails from the dropdown are sent.
    In the functions.php from my theme, the “woocommerce_order_action_…” is executed (it adds me a note to the order). Also, the constructor who extends the WC_Email class is executed correctly every page load (I added error_log(“Test”); ). I also added transactional triggers to the constructor of my custom email class, like copied below. Then the Mail is sent one time by creating the order, but by selecting the “custom dropdown mail” / triggering the “woocommerce_order_action_…” it doesn’t get sent.

    // Triggers for this email.
    			add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
    
    			add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
    			add_action( 'woocommerce_order_status_cancelled_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
    			add_action( 'woocommerce_order_status_on-hold_to_processing_notification', array( $this, 'trigger' ), 50, 2 );
    			
    			add_action( 'woocommerce_order_action_mahnung', array( $this, 'trigger' ) );
    Mirko P.

    (@rainfallnixfig)

    Hi there,

    This is more of a development-oriented issue and we do not provide support for custom coding on these forums. WooCommerce core forum only covers support for the default features and functionality that come with WooCommerce.

    You can check what’s been updated in WooCommerce 6.0 here:

    https://developer.woocommerce.com/2021/12/15/woocommerce-6-0-released/

    If you need more help trying to figure out what changes you should make to your custom code, I recommend you visit the official WooCommerce Facebook Group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thanks.

    Thread Starter terpentin

    (@terpentin)

    Hi everyone,
    I solved the problem in the following manner: I don’t trust the trigger in the Email class, so I deleted it here. Then I added the following code in my functions to trigger the email there:

    function mahnung_order_meta_box_action( $order ) {
      //$message = "Mahnung gesendet.";
      //$order->add_order_note( $message );
    
      $mails = WC()->mailer()->get_emails();
    
      if ( isset( $mails['WC_Mahnung_Email_Manual'] ) ) {
        $mails['WC_Mahnung_Email_Manual']->trigger( $order );
      }
    }
    add_action( 'woocommerce_order_action_mahnung', 'mahnung_order_meta_box_action' );
    

    Thanks for letting us know!

    Thank you for sharing your solution that would help in case anyone else has a similar inquiry.

    I’ll mark this thread as resolved. If you have any further questions, I recommend creating a new thread.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Custom Email From Order Action Dropdown’ is closed to new replies.