I get an error from this function when we request this shortcode
function salex_func( $atts ){
global $product;
if($product->is_on_sale()){
echo '<span class="onsale soldout">';
echo __( 'SALE!!!!', 'hello');
echo '</span>';
}
}
add_shortcode('saletex', 'salex_func');
2
Answers
You can’t echo shortcode output. You have to return it.
You don’t need to echo inside the shortcode function.
You can try this code: