• Resolved niklas.buschner

    (@niklasbuschner)


    WooCommerce Germanized offers an integrated management of DHL shipments and also provides an e-mail that is sent to users.

    In the shop, a shipment is created and marked as “shipped”, but the customer receives a strange mix by mail from the refund and shipping notification. The subject and header of the mail is refund, but the content of the mail is related to the shipping notification as desired.

    We have checked the problem and the problem arises when WooCommerce Multilingual is activated. Without WooCommerce Multilingual the problem does not arise. We have already communicated this to WooCommerce Germanized. We were asked to communicate this to the WooCommerce Multilingual team as well.

Viewing 14 replies - 1 through 14 (of 14 total)
  • sergey.r

    (@sergeyr-1)

    Hello Niklas,
    do you have a support ticket on wpml.org forum?

    Thread Starter niklas.buschner

    (@niklasbuschner)

    Just now

    Thread Starter niklas.buschner

    (@niklasbuschner)

    So I received support from the plugin author of WooCommerce Germanized and WPML now. Unfortunately there seems to be confusion on the WPML site, because I was provided with a fix that (according to the plugin author of WooCommerce Germanized, who also provided me with a fix) has nothing to do with my actual problem. The plugin author of WooCommerce Germanized now suggested to post my problem here so it receives a decent solution.

    The plugin author of WooCommerce Germanized provided the following fix. In inc/class-wcml-emails.php of WooCommerce Multilingual you see this code:

    public function filter_refund_emails_strings( $value, $object, $old_value, $key ) {
    
        if ( in_array( $key, array(
                'subject_partial',
                'subject_full',
                'heading_partial',
                'heading_full'
            ) ) && $object->object ) {
            $translated_value = $this->get_refund_email_translated_string( $key, $object );
        }
    
        return ! empty( $translated_value ) ? $translated_value : $value;
    }

    There I should check above $object, which e-mail object it is. Example:

    if ( ! in_array( $email->id, array( 'customer_refund_order' ) ) ) {
        return $value;
    }

    This worked, so when I sent a Tracking notification via WooCommerce Germanized the customer actually received the mail with the right subject and header and not the subject that the order was refunded.

    Only problem is that I don’t see how to implement a translation, since I get the following warning in the WooCommerce mail configuration fields, which prevents me from implemented translatable strings there:

    Undefined variable: email in .../wp-content/plugins/woocommerce-multilingual/inc/class-wcml-emails.php on line 301 Notice: Trying to get property 'id' of non-object in .../wp-content/plugins/woocommerce-multilingual/inc/class-wcml-emails.php on line 301

    Now WPML support provided me with this fix:

    In wp-content/plugins/woocommerce-germanized/packages/woocommerce-germanized-shipments/templates/emails/customer-shipment.php after line 19 add:

    /*
     * WPML fix: send mail in the order lang, not in the admin lang
     */
    if (class_exists('sitepress')) {
        $current_lang = apply_filters( 'wpml_current_language', NULL );
        $order_lang = get_post_meta( $order->id, 'wpml_language', true );
        if ($order_lang != '') {
            do_action( 'wpml_switch_language', $order_lang );
        }
    }

    and after line 80:

    /*
     * WPML fix: send mail in the order lang, not in the admin lang. Switch back to current lang
     */
    if (class_exists('sitepress')) {
        do_action( 'wpml_switch_language', $current_lang );
    }

    According to the plugin author of WooCommerce Germanized this has nothing to do with my actual problem and the ticket at WPML was already closed.

    Since I am engaged in the tickets for quite a while now and don’t really see any progress in the matter other than the fix provided by WooCommerce Germanized plugin author, I hope that my post helps to find a solution.

    Hello Niklas,
    can you please describe a problem here and provide a steps to reproduce?

    And I’ll check your issue on next week ( I’m off next days ).

    Thanks a lot!

    Thread Starter niklas.buschner

    (@niklasbuschner)

    Hello Sergey,

    I already did this in the first post but I can post it again:

    WooCommerce Germanized offers an integrated management of DHL shipments and also provides an e-mail that is sent to users.

    In the shop, a shipment is created and marked as “shipped”, but the customer receives a strange mix by mail from the refund and shipping notification. The subject and header of the mail is refund, but the content of the mail is related to the shipping notification as desired.

    We have checked the problem and the problem arises when WooCommerce Multilingual is activated. Without WooCommerce Multilingual the problem does not arise. We have already communicated this to WooCommerce Germanized. We were asked to communicate this to the WooCommerce Multilingual team as well.

    Hello Niklas,
    I’m asking about detailed steps ( what should I do to see this issue ), or it’s happened for new order email?

    Thread Starter niklas.buschner

    (@niklasbuschner)

    Hello Sergey, I already went through the whole process with the official WPML support and they also provided a staging environment where I reproduced the issue.

    1. Customer buys something
    2. We create a shipping with the integrated DHL API from WooCommerce Germanized plugin
    3. Customer should receive a mail that says ‘Your order is shipped’ but instead (when WooCommerce Multilingual is active) receives ‘Your order is refunded’

    We tracked down the issue to being related with WooCommerce Multilingual

    Is this detailed enough for you?

    Here ist the link to the official WPML ticket: https://wpml.org/forums/topic/woocommerce-multilingual-and-woocommerce-germanized-compatibility-issue/

    Thanks a lot for steps and a link ( I’ll ask an Andreas if I need more info )

    I’ll get to you when I have a fix for your issue ( probably on next week ).

    Thread Starter niklas.buschner

    (@niklasbuschner)

    Hey Sergey thanks for your quick reply!

    Thread Starter niklas.buschner

    (@niklasbuschner)

    Hey Sergey, when can I expect your reply? Just to give you a quick heads-up on what is working now and what is not.

    I implemented the following code in class-wcml-emails.php. This is basically the fix the author of WooCommerce Germanized suggested.

    public function filter_refund_emails_strings( $value, $object, $old_value, $key ) {
            
            if ( ! in_array( $email->id, array( 'customer_refund_order' ) ) ) {
                return $value;
            }
    
    		if ( in_array( $key, array(
    				'subject_partial',
    				'subject_full',
    				'heading_partial',
    				'heading_full'
    			) ) && $object->object ) {
    			$translated_value = $this->get_refund_email_translated_string( $key, $object );
    		}
    
    		return ! empty( $translated_value ) ? $translated_value : $value;
    	}

    With this fix, the customers receive the tracking notification of WooCommerce Germanized correctly but only in the German language.

    Now I additionally implemented the fix provided by WPML team:

    In wp-content/plugins/woocommerce-germanized/packages/woocommerce-germanized-shipments/templates/emails/customer-shipment.php after line 19 add:

    /*
     * WPML fix: send mail in the order lang, not in the admin lang
     */
    if (class_exists('sitepress')) {
        $current_lang = apply_filters( 'wpml_current_language', NULL );
        $order_lang = get_post_meta( $order->id, 'wpml_language', true );
        if ($order_lang != '') {
            do_action( 'wpml_switch_language', $order_lang );
        }
    }

    and after line 80:

    /*
     * WPML fix: send mail in the order lang, not in the admin lang. Switch back to current lang
     */
    if (class_exists('sitepress')) {
        do_action( 'wpml_switch_language', $current_lang );
    }

    This works partially, since the body text of the shipment notification is now correctly translated to english if the order language is englisch.

    But what is still not working as expected is the mail subject and header. If I write nothing into the mail administration input fields, I receive the php warnings described earlier:

    Undefined variable: email in .../wp-content/plugins/woocommerce-multilingual/inc/class-wcml-emails.php on line 301 Notice: Trying to get property 'id' of non-object in .../wp-content/plugins/woocommerce-multilingual/inc/class-wcml-emails.php on line 301

    If I put strings into the input fields, those are correctly saved and used but even with a string scan through WPML plugin localization, I don’t get correctly translated header and subject strings for the shipment notification mail.

    What is really strange now, is that when I searched for english equivalents of the german shipment notification strings, those seem to be correctly implemented but not used. Now I tried to make a translation vice-versa, where I put my german strings that I put into the mail administration, into the WPML string translation, but this also did not work.

    Actually I find it quite hard to handle two support tickets and a forum thread. I would highly appreciate a decent and complete fix or workaround, since the current situation is disappointing for me and my client.

    Thanks!

    Thread Starter niklas.buschner

    (@niklasbuschner)

    EDIT for my reply above: Not all body texts of the shipment notifications are correctly translated. I already notified the plugin author of WooCommerce Germanized about this and he told me that it would require some more detailed work on the translation support for the shipment notification mails in WPML.

    Thread Starter niklas.buschner

    (@niklasbuschner)

    Further notice: What seems strange to me, is that we have 3 translation input fields in the string translation. I thought that this may be related to the implementation of the de_DE_formal language files which we did while the shop was already up and running. Concerning this I also noticed a lot of JSON files in the wp-content/languages/ and wp-content/languages/plugins folder (screenshot below). Do you see a connection between this?

    https://imgur.com/Bpnj5Ly

    Hello Nicklas,
    this issue in my list of tasks but it requires time for a fix. I’ll update you as soon as I have results.

    About ” a lot of JSON files in the wp-content/languages/” it’s how WPML ST works now ( for better performance )

    Thanks for your patience and updates!

    • This reply was modified 4 years, 11 months ago by sergey.r.

    Hello Nicklas,
    Thanks for your patience!

    I have checked WooCommerce Germanized plugin code and noticed that they used a little bit different logic in emails than WooCoomerce and it requires adding a compatibility code to both plugins ( our and WooCommerce Germanized ). I have pinged our Compatibility team and they will work with plugin author to resolve all compatibility problems ( I can’t estimate when it will happen ).

    As a temporary solution instead of code above you can add the following:

    if ( class_exists( 'sitepress' ) ) {
    		            $order_lang = get_post_meta( $order_shipment->get_order()->get_id(), 'wpml_language', true );
    		            if ( $order_lang ) {
    			            do_action( 'wpml_switch_language', $order_lang );
    		            }
    	            }

    into WC_GZD_Email_Customer_Shipment::triger
    after if ( $this->is_enabled() && $this->get_recipient() ) {

    line and it will work for default strings ( Please note if you will enter custom subject in email settings it will not apper as translated because you will need to register these string first )

    Here you can check how email looks to me now https://clip2net.com/s/452UsNP

    • This reply was modified 4 years, 11 months ago by sergey.r.
    • This reply was modified 4 years, 11 months ago by sergey.r.
    • This reply was modified 4 years, 11 months ago by sergey.r.
Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘WooCommerce Multilingual and WooCommerce Germanized compatibility issue’ is closed to new replies.