• Resolved Paul

    (@paulschiretz)


    Hi, thanks for trying to fix the deprecation notice on emails.

    * Fixed deprecated notice when translating WooCommerce emails

    I tested the last version 2.8.3 where your change log states this should be resolved but still it isn’t.

    I can see you tried to resolve it by adding checks (line 147 to 151 of class-woocommerce-emails):

           if ( $recipients === null || $recipients === '' ) {
    $recipients = [];
    } elseif ( !is_array($recipients) ) {
    $recipients = explode( ',', $recipients );
    }

    but just before those checks you are calling:

            $recipients         = $wc_email->get_recipient();

    To get the recipients BUT wc_email->get_recipient() internally uses this code:

    	/**
    * Get valid recipients.
    *
    * @return string
    */
    public function get_recipient() {
    $recipient = apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object, $this );
    $recipients = array_map( 'trim', explode( ',', $recipient ) );
    $recipients = array_filter( $recipients, 'is_email' );
    return implode( ', ', $recipients );
    }

    Which basically means your fix solves nothing cause the first explode on null is already called inside the get_recipient() function of woocommerce. the only way around this is to write a filter for each email id and return “” instead of null for the recipient IF you need to hook trp_woo_setup_locale before the wc_email recipient is set up.

    Can you have another look at that?

    Cheers,
    Paul

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Paul

    (@paulschiretz)

    Something like that would be a workaround:

    add_filter('woocommerce_email_recipient_customer_on_hold_order', 'custom_typesafe_email_recipient', 10, 3);
    add_filter('woocommerce_email_recipient_customer_processing_order', 'custom_typesafe_email_recipient', 10, 3);
    add_filter('woocommerce_email_recipient_customer_completed_order', 'custom_typesafe_email_recipient', 10, 3);
    add_filter('woocommerce_email_recipient_customer_refunded_order', 'custom_typesafe_email_recipient', 10, 3);
    add_filter('woocommerce_email_recipient_customer_invoice', 'custom_typesafe_email_recipient', 10, 3);
    add_filter('woocommerce_email_recipient_customer_note', 'custom_typesafe_email_recipient', 10, 3);
    add_filter('woocommerce_email_recipient_customer_reset_password', 'custom_typesafe_email_recipient', 10, 3);
    add_filter('woocommerce_email_recipient_customer_new_account', 'custom_typesafe_email_recipient', 10, 3);
    function custom_typesafe_email_recipient($recipient, $object, $email) {
    if( is_null($recipient) ) {
    return "";
    }
    return $recipient;
    }

    but it’s not really a fix.

    Thread Starter Paul

    (@paulschiretz)

    But the real issue is you are hooking into setup_locale() and expect the recipient to be set up. but this is the woocommerce code to trigger the sending of emails to the customer:

    		/**
    * Trigger the sending of this email.
    *
    * @param int $order_id The order ID.
    * @param WC_Order|false $order Order object.
    */
    public function trigger( $order_id, $order = false ) {
    $this->setup_locale();

    if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
    $order = wc_get_order( $order_id );
    }

    if ( is_a( $order, 'WC_Order' ) ) {
    $this->object = $order;
    $this->recipient = $this->object->get_billing_email();
    $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
    $this->placeholders['{order_number}'] = $this->object->get_order_number();
    }

    if ( $this->is_enabled() && $this->get_recipient() ) {
    $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
    }

    $this->restore_locale();
    }

    you can clearly see the recipient is set up after setup_locale(); is triggered. So you cannot expect to call get_recipient() on wc_email and get something valid back.
    The workaround posted before is functioning but it only hides the problem, and your plugin clearly has an issue there. Please have another look at that.

    Cheers,
    Paul

    Plugin Support Alex

    (@alexcozmoslabs)

    Hi,

    I reach our dev team about this. My colleagues will investigate in details and find a proper solution.


    Best Regards,

    Plugin Support Alex

    (@alexcozmoslabs)

    We will try to fix this in one of the next plugin updates.

    Thank you for understanding.

    Thread Starter Paul

    (@paulschiretz)

    Thank you! The issue is fixed in 2.8.9!
    Cheers,
    Paul

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.