• Resolved ledspros

    (@ledspros)


    Hello,
    I have some trouble to translate “En cours d’approvisionnement”.
    I have try with loco translate, but unfortunality without success…
    Do you know how to replace “En cours d’approvisionnement” by “Livraison 5 à 8 jours”.
    If you let me an e-mail, I could send you a picture.
    Thanks for your help,
    Best Regards,
    Leds-Pros

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! This is the translation of ‘Backordered’ – this is part of the WooCommerce text domain… The tricky thing is, that once this is added to the order, changing the translations will not affect this string anymore, because it is stored in the order item meta. The only way to change this is to edit the order item meta directly in the backend, but paid orders cannot be edited.

    So three strategies to change this:
    1) Editing paid orders
    You need to apply the following filter:

    
    add_filter( 'wc_order_is_editable', '__return_true', 10, 2 );
    

    2a) Change the string in the WooCommerce text domain
    In loco translate, open the strings for WooCommerce rather than PDF Invoices & Packing Slips

    2b) Use a filter to change the string (instead of loco translate)
    Instead of using Loco translate, you can also replace the string with a filter. This allows for more dynamic behavior, although this example just replaces it the same for all products:

    
    add_filter( 'woocommerce_backordered_item_meta_name', 'woocommerce_backordered_item_meta_name', 10, 2 );
    function woocommerce_backordered_item_meta_name( $name, $product ) {
    	return 'Livraison 5 à 8 jours';
    }
    

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    Hope that helps!

    Thread Starter ledspros

    (@ledspros)

    Hello,
    I have tryed to add 2b) on function.php but nothing change…
    May I give you an admin access in private content to check the problem ?
    Thanks for your help

    • This reply was modified 5 years, 7 months ago by ledspros.
    • This reply was modified 5 years, 7 months ago by ledspros.
    Plugin Contributor Ewout

    (@pomegranate)

    Hi! 2b) will not have any effect on existing orders, for that you will need to do 1).

    Thread Starter ledspros

    (@ledspros)

    Sorry. may I have to write the both 1) and 2) ?
    It seems that if I copy 1) in function.php it broke the website…

    Thread Starter ledspros

    (@ledspros)

    Hello, do you received my last message ?

    Plugin Contributor Ewout

    (@pomegranate)

    Yes you can combine solutions 1 & 2. If this broke your website, it’s likely that you made a copy paste error. I recommend using Code Snippets instead, it’s safer.

    Thread Starter ledspros

    (@ledspros)

    Sorry,but
    1/ I have copy all codes in function.php
    2/ translated “backordered” by “Livraison 5 à 8 jours” in locotranslate/plugin/woocommerce” but no changes…

    add_filter( ‘wc_order_is_editable’, ‘__return_true’, 10, 2 );
    add_filter( ‘woocommerce_backordered_item_meta_name’, ‘woocommerce_backordered_item_meta_name’, 10, 2 );
    function woocommerce_backordered_item_meta_name( $name, $product ) {
    return ‘Livraison 5 à 8 jours’;
    }

    Plugin Contributor Ewout

    (@pomegranate)

    Part 1) is so that you can enable editing of the existing orders. The translation and filter will only affect new orders

    Thread Starter ledspros

    (@ledspros)

    Effectively, it works with only new orders.
    Thanks for help,
    Best Regards

    Plugin Contributor Ewout

    (@pomegranate)

    And for existing orders, you can edit the meta in line items inside the order and change the text!

    Thread Starter ledspros

    (@ledspros)

    Ok, thanks for all

    Thread Starter ledspros

    (@ledspros)

    Hi,
    Few times ago, you give me a code to delete the line “En cours d’approvisionnement”. It is working perfectly. But is it possible to remove the line only for invoice and delivery order, but let the line to the quote ?
    This is your code:

    add_action( ‘wpo_wcpdf_before_html’, ‘wpo_wcpdf_item_meta_remove_backordered’ );
    function wpo_wcpdf_item_meta_remove_backordered() {
    add_filter( ‘woocommerce_order_item_get_formatted_meta_data’, ‘woocommerce_order_item_meta_remove_backordered’, 10, 2 );
    }
    function woocommerce_order_item_meta_remove_backordered( $formatted_meta, $item ) {
    foreach ( $formatted_meta as $meta_id => $meta ) {
    if ($meta->display_key == apply_filters( ‘woocommerce_backordered_item_meta_name’, __( ‘Backordered’, ‘woocommerce’ ), $item ) ) {
    unset($formatted_meta[$meta_id]);
    }
    }
    return $formatted_meta;
    }

    Plugin Contributor Ewout

    (@pomegranate)

    Yes you can do this with a small modification:

    
    add_action( 'wpo_wcpdf_before_html', 'wpo_wcpdf_item_meta_remove_backordered', 10, 2 );
    function wpo_wcpdf_item_meta_remove_backordered( $document_type, $document = null ) {
        if ($document_type == 'invoice') {
            add_filter( 'woocommerce_order_item_get_formatted_meta_data', 'woocommerce_order_item_meta_remove_backordered', 10, 2 );
        }
    }
    function woocommerce_order_item_meta_remove_backordered( $formatted_meta, $item ) {
        foreach ( $formatted_meta as $meta_id => $meta ) {
            if ($meta->display_key == apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ), $item ) ) {
                unset($formatted_meta[$meta_id]);
            }
        }
        return $formatted_meta;
    }
    
    Thread Starter ledspros

    (@ledspros)

    Hello,
    Thanks,
    1/ “En cours d’approvisionnement” disappeared on invoice: Great !
    2/ “En cours d’approvisionnement” is translated by “Livraison 5 à 8 jours” and appears on quote: very great !
    3/ But it doesn’t disappeared on Delivery shipping ( packing slip )…
    For information I let all codes you let me:

    add_filter( ‘wc_order_is_editable’, ‘__return_true’, 10, 2 );
    add_filter( ‘woocommerce_backordered_item_meta_name’, ‘woocommerce_backordered_item_meta_name’, 10, 2 );
    function woocommerce_backordered_item_meta_name( $name, $product ) {
    return ‘Livraison 5 à 8 jours’;
    }

    add_action( ‘wpo_wcpdf_before_html’, ‘wpo_wcpdf_item_meta_remove_backordered’, 10, 2 );
    function wpo_wcpdf_item_meta_remove_backordered( $document_type, $document = null ) {
    if ($document_type == ‘invoice’) {
    add_filter( ‘woocommerce_order_item_get_formatted_meta_data’, ‘woocommerce_order_item_meta_remove_backordered’, 10, 2 );
    }
    }
    function woocommerce_order_item_meta_remove_backordered( $formatted_meta, $item ) {
    foreach ( $formatted_meta as $meta_id => $meta ) {
    if ($meta->display_key == apply_filters( ‘woocommerce_backordered_item_meta_name’, __( ‘Backordered’, ‘woocommerce’ ), $item ) ) {
    unset($formatted_meta[$meta_id]);
    }
    }
    return $formatted_meta;
    }

    Plugin Contributor Ewout

    (@pomegranate)

    that’s correct, this filter to remove the meta will not work properly if you keep changing the strings 🙂

    This may work:

    
    add_action( 'wpo_wcpdf_before_html', 'wpo_wcpdf_item_meta_remove_backordered', 10, 2 );
    function wpo_wcpdf_item_meta_remove_backordered( $document_type, $document = null ) {
        if ($document_type == 'invoice') {
            add_filter( 'woocommerce_order_item_get_formatted_meta_data', 'woocommerce_order_item_meta_remove_backordered', 10, 2 );
        }
    }
    function woocommerce_order_item_meta_remove_backordered( $formatted_meta, $item ) {
        foreach ( $formatted_meta as $meta_id => $meta ) {
            if ($meta->display_key == apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ), $item ) ||  $meta->display_key == __( 'Backordered', 'woocommerce' ) || stripos($meta->display_key, 'Livraison ') !== false ) {
                unset($formatted_meta[$meta_id]);
            }
        }
        return $formatted_meta;
    }
    
    • This reply was modified 5 years, 7 months ago by Ewout. Reason: added extra option
Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Translation’ is closed to new replies.