1
I am building a Wordpress site with Woocommerce and want to make the check that if there are products on sale with the shortcode, if exist returns me the title + products, if there is no product on sale the block some. I had some ideas and one of them was:
<?php
//Produtos em promoção
//Armazena o shortcode ( mas acredito estar errado )
$produto_promocao = do_shortcode('[sale_products limit="4" columns="4" orderby="popularity" class="quick-sale" on_sale="true" ]');
//Verifica se existe os produtos, se existir, exibe o titulo e os produtos por
//meio do shortcode, caso ao contrario, retorna vazio
if($produto_promocao != false){
_e( 'Promotional Products', 'wordpress' ); //Exibe titulo
echo $produto_promocao; //Exibe produtos
} else {
return ''; //Retorna vazio
}
?>
But it didn’t work, and I can only imagine why. I imagine I need some identifier for the products on sale, or make some other logic.. I accept constructive criticism, I am training ! I apologize beforehand already if I have not graduated here right, I am beginner. Hugs
Man, thank you so much ! Super worked, I just added the title just above the echo shortcode. Please, could you explain your line of thought ? I would like to understand how you thought to reach this solution ! Hugs
– Elton Miranda
Dude, basically I created a function by defining a variable and filtering the ids of the products on sale through the event "wc_get_product_ids_on_sale", which comes from Woocommerce, to be able to make the comparison right below. Go to this page ( https://docs.woocommerce.com/wc-apidocs/package-WooCommerce.Functions.html ), and check out the available methods.
– Brício Fernandes