0

I added this function to add cash on delivery price and I want to translate the text (cash on delivery) using WPML plugin

add_action( 'woocommerce_cart_calculate_fees', 'custom_handling_fee', 10, 1 );
function custom_handling_fee ( $cart ) {

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( 'cod' === WC()->session->get('chosen_payment_method') ) {
        $fee = 10;
        $cart->add_fee( 'Cash On Delivery', $fee, true );
    }
}
1

It should suffice to add a __() around your translatable text:

add_action( 'woocommerce_cart_calculate_fees', 'custom_handling_fee', 10, 1 );
function custom_handling_fee ( $cart ) {

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( 'cod' === WC()->session->get('chosen_payment_method') ) {
        $fee = 10;
        $cart->add_fee( __('Cash On Delivery'), $fee, true );
    }
}

You can then scan your theme or plugin for strings in WPML: https://wpml.org/documentation/getting-started-guide/theme-localization/ and then use the WPML string translation.

  • Works Fine ! Thanks a lot – bsomar Nov 19 at 10:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.