最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - How to translate text in function.php with WPML

programmeradmin1浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

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 );
    }
}
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

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 );
    }
}
Share Improve this question edited Nov 23, 2019 at 19:57 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Nov 13, 2019 at 7:25 bsomarbsomar 133 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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/documentation/getting-started-guide/theme-localization/ and then use the WPML string translation.

发布评论

评论列表(0)

  1. 暂无评论