Created
August 13, 2024 13:23
-
-
Save tdmrhn/55d4cd235d47c17602b347d8d23ce5f6 to your computer and use it in GitHub Desktop.
Show Best Seller Products in Empty Woo Categories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://woocommerce.github.io/code-reference/files/woocommerce-templates-archive-product.html | |
add_action('woocommerce_no_products_found', function () { | |
// Display the bestsellers | |
echo '<h2>Our Bestsellers</h2>'; | |
echo do_shortcode('[best_selling_products per_page="6" columns="3"]'); // https://woocommerce.com/document/woocommerce-shortcodes/products/ | |
// Display a button to go to the shop page | |
echo '<div class="ct-container">'; | |
echo '<a class="ct-button" href="' . esc_url(get_permalink(wc_get_page_id('shop'))) . '">All Products</a>'; | |
echo '</div>'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment