Support » Plugin: WooCommerce » Shortcode to display product titles only

  • Hello,

    Is there a shortcode (or a code snippet) for displaying the titles only of all the products in a category? The default shortcode shows the thumbnail, price, buttons, etc.

    Thank you,
    Ryan

Viewing 1 replies (of 1 total)
  • You can use the shortcode [products_by_category_slug product_cat=”category-slug” orderby=”rand”] by adding the below conde in theme function.php file.

    <?php

    add_shortcode( ‘products_by_category_slug’, ‘products_by_category_slug’ );
    function products_by_category_slug( $atts, $content = null ) {
    extract( shortcode_atts( array(
    ‘product_cat’ => ”,
    ‘orderby’ => ‘rand’,
    ), $atts));
    ?>
    <ul class=”products”>
    <?php
    $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, ‘product_cat’ =>$product_cat, ‘orderby’ => $orderby);
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
    <li class=”product”>
    post->ID ) ?>” title=”<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>”>
    <h3><?php the_title(); ?></h3>

    <?php endwhile; ?>
    <?php wp_reset_query(); ?>

    <?php
    }
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Shortcode to display product titles only’ is closed to new replies.