简体   繁体   中英

WooCommerce products not appearing unless using WP_Query

I have added four products to WooCommerce but none are showing up on the shop page. I can't even see the product if I click the link to view it in the backend. I have tried resetting the permalinks in settings and I have made sure that each products Catalog visibility is set to "Shop and search results". And I have also deactivated every plugin apart from WooCommerce and still no products on the front end.

The weird thing is that the products will show on any page that I use WP_Query like so:

<?php
    $params = array('posts_per_page' => 5, 'post_type' => 'product');
    $wc_query = new WP_Query($params);
?>
<?php if ($wc_query->have_posts()) : ?>
    <?php while ($wc_query->have_posts()) :
        $wc_query->the_post(); ?>
    <?php the_title(); ?>
    <?php endwhile; ?>
    <?php wp_reset_postdata(); ?>
<?php else:  ?>

<p><?php _e( 'No Products'); ?></p>

<?php endif; ?>

Is there anything else I can try?

It seems the products only don't show on my custom theme. If I make one of the standard themes that come with wp active it shows the products. What is causing this?

Do your theme support woocommerce?

if yes did you set the shop page?

you will find the setting Dasbord->Woocommerce->settings>product->Shop pages

This link might help you

If You are using Custom theme then you have to add archive-product.php to your theme.

You can add that template by creating a folder in your theme name "Woocommerce" then in that folder copy archive-product.php from ---Plugins->Woocommerce->templates and paste in themes Woocommerce template.

(Note : you are running custom theme this is why issue occurs).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM