How can I display the category name on [recent_products] WooCommerce shortcode?

I am trying to grab the category name of recent products in WooCommerce. I am using

[recent_products per_page="12" columns="4"]

The Recent Products code is in class-wc-shortcodes.php

public static function recent_products( $atts ) {
    $atts = shortcode_atts( array(
        'per_page'  => '12',
        'columns'   => '4',
        'orderby'   => 'date',
        'order'     => 'desc'
    ), $atts );

    $query_args = array(
        'post_type'           => 'product',
        'post_status'         => 'publish',
        'ignore_sticky_posts' => 1,
        'posts_per_page'      => $atts['per_page'],
        'orderby'             => $atts['orderby'],
        'order'               => $atts['order'],
        'meta_query'          => WC()->query->get_meta_query()
    );

    return self::product_loop( $query_args, $atts, 'recent_products' );
}


Source: shortcode

Leave a Reply