Translating Wordpress (WooCommerce plugin) using php filters
Get the solution ↓↓↓I am trying to translate my WooCommerce page to my native language using php filterss (add_filter() function). I got one example where I took a hook of the page and used it to easily translate a button without any issue.
add_filter('ultimate_woocommerce_auction_bid_button_text', 'woo_custom_bid_button_text');
function woo_custom_bid_button_text() {
return __( 'PЕ™ihodit', 'woo_ua' );
}
"PЕ™ihodit" is a translation to my native language of "Place bid".
Problem is when I want to translate part right in front of the button which says "Bid Value"
This is WooCommerce source code:
<div class="quantity buttons_added">
<label for="uwa_your_bid"><?php _e('Bid Value', 'woo_ua') ?>:</label>
<input type="number" name="uwa_bid_value" data-auction-id="<?php echo esc_attr( $product_id ); ?>"
value=""min="<?php echo $product->woo_ua_bid_value() ?>"
step="any" size="<?php echo strlen($product->get_woo_ua_current_bid())+2 ?>" title="bid" class="input-text qty bid text left">
</div>
I have already tried using same method as I used above:
add_filter('ultimate_woocommerce_auction_before_bid_button', 'woo_custom_text_before_bid_input'`enter code here`);
function woo_custom_text_before_bid_input() {
return _e('PЕ™Гhoz', 'woo_ua');
}
But I cant get this to work since theres not a specific hook to use. Thanks to any replies or solutions in advance.
Answer
Solution:
You could use gettext filter
add_filter( 'gettext', function( $translated_text, $text, $domain ){
if ( $text == 'Bid Value' )
$translated_text = 'PЕ™Гhoz';
return $translated_text;
}, 10, 3 );
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: apache/2.4.52 (win64) openssl/1.1.1m php/8.1.2 server at localhost port 80
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.