• Hi,

    I added this code into my website to display a badge.
    This works great but my site is multilingual.

    I want to know how to translate the “sold out”

    What should I add to make it detected by poedit?

    //* Do NOT include the opening php tag
    //* Add sold out badge on single product pages
    add_action( ‘woocommerce_before_single_product_summary’, function() {
    global $product;
    if ( !$product->is_in_stock() ) {
    echo ‘<span class=”soldout”>Sold out</span>’;
    }
    });

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    You can translate the Sold out text by using one of the functions that WordPress provide for translations. For example the esc_html__() function.

    So, your code should be

    echo '<span class="soldout">' . esc_html__( 'Sold Out', 'textdomain' ) . '</span>';

    Regarding the text domain depend by your theme or plugin. In your case may be ‘woocommerce’.

    Thread Starter eltrinita

    (@eltrinita)

    Thank you for your answer

    i get this: Parse error: syntax error, unexpected ‘Recréable’ (T_STRING), expecting ‘,’ or ‘;’ in /wp-content/themes/enfold-child/functions.php on line 38

    Below the entire code. Tested and no parse errore is showing.
    May be you missed a semi-colon at the end of the echo?

    add_action( 'woocommerce_before_single_product_summary', function () {
    
    	global $product;
    	if ( ! $product->is_in_stock() ) {
    		echo '<span class="soldout">' . esc_html__( 'Sold Out', 'textdomain' ) . '</span>';
    	}
    } );
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Help for a little translation’ is closed to new replies.