【发布时间】:2021-11-01 22:40:54
【问题描述】:
根据语言更改字符串。翻译字符串有更好的解决方案吗?有没有办法缩短代码。谢谢。
<?php
add_action( 'woocommerce_before_cart_table', 'cart_page_notice' );
function cart_page_notice() {
$min_amount = 1000; //This is the amount of your free shipping threshold. Change according to your free shipping settings
$current = WC()->cart->subtotal;
if (( $current < $min_amount ) && ICL_LANGUAGE_CODE == 'ru') {
$added_text = '<div class="woocommerce-message"><strong>Купите еще на ' . wc_price( $min_amount - $current ) . ' для бесплатной доставки</strong>'; // This is the message shown on the cart page
$return_to = wc_get_page_permalink( 'shop' );
if(ICL_LANGUAGE_CODE == 'ru'){
$notice = sprintf( '%s<a class="button" href="%s">%s</a>', $added_text, esc_url( $return_to ), 'Продолжить покупки</div>' ); // This is the text shown below the notification. Link redirects to the shop page
echo $notice;
}
}if (( $current < $min_amount ) && ICL_LANGUAGE_CODE == 'en') {
$added_text = '<div class="woocommerce-message"><strong>Buy ' . wc_price( $min_amount - $current ) . ' worth products more to get free shipping</strong>'; // This is the message shown on the cart page
$return_to = wc_get_page_permalink( 'shop' );
if(ICL_LANGUAGE_CODE == 'en'){
$notice = sprintf( '%s<a class="button" href="%s">%s</a>', $added_text, esc_url( $return_to ), 'Continue shopping</div>' ); // This is the text shown below the notification. Link redirects to the shop page
}
echo $notice;
}elseif (( $current < $min_amount ) && ICL_LANGUAGE_CODE == 'tr') {
$added_text = '<div class="woocommerce-message"><strong>Ücretsiz kargo için ' . wc_price( $min_amount - $current ) . ' daha satın alın</strong>'; // This is the message shown on the cart page
$return_to = wc_get_page_permalink( 'shop' );
if(ICL_LANGUAGE_CODE == 'tr'){
$notice = sprintf( '%s<a class="button" href="%s">%s</a>', $added_text, esc_url( $return_to ), 'Alışverişe devam</div>' ); // This is the text shown below the notification. Link redirects to the shop page
}
echo $notice;
}
}
【问题讨论】:
-
在Code Review问这个问题
标签: php wordpress woocommerce code-snippets wpml