• Hello everyone,

    I am having problems with WooCommerce, and their support forum has been down for the passed 2 days. Basically, they have shortcodes in the shortcode button in the page editor that is not documented in their docs, and it is not working. I want to create a page with all categories on it, and there is a shortcode [product_categories number=””] that looks like it should do that, but alas it is not working.

    I looked in the shortcode PHP file and found the following:

    /**
     * List all (or limited) product categories
     **/
    function woocommerce_product_categories( $atts ) {
    	global $woocommerce_loop;
    
    	extract( shortcode_atts( array (
    		'number'     => null,
    		'orderby'    => 'name',
    		'order'      => 'ASC',
    		'columns' 	 => '4',
    		'hide_empty' => 1
    		), $atts ) );
    
    	if ( isset( $atts[ 'ids' ] ) ) {
    		$ids = explode( ',', $atts[ 'ids' ] );
    	  	$ids = array_map( 'trim', $ids );
    	} else {
    		$ids = array();
    	}
    
    	$hide_empty = ( $hide_empty == true || $hide_empty == 1 ) ? 1 : 0;
    
      	$args = array(
      		'number'     => $number,
      		'orderby'    => $orderby,
      		'order'      => $order,
      		'hide_empty' => $hide_empty,
    		'include'    => $ids
    	);
    
      	$terms = get_terms( 'product_cat', $args );
    
      	$woocommerce_loop['columns'] = $columns;
    
      	ob_start();
    
      	if ( $product_categories ) {
    
      		echo '<ul class="products">';
    
    		foreach ( $product_categories as $category ) {
    
    			woocommerce_get_template( 'content-product_cat.php', array(
    				'category' => $category
    			) );
    
    		}
    
    		echo '</ul>';
    
    	}
    
    	wp_reset_query();
    
    	return ob_get_clean();
    }

    Any thoughts?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • It’s strange it isn’t working for you, because I got it working just fine. Do you have any products in your categories? No products = no categories displayed.

    Thread Starter mrapino

    (@mrapino)

    Yes,

    I do have a category with products associated with it, so I;m not sure what the issue is. When you use [product_categories number=””], what do you put in between the quotes for number? I tried blank, I tried a couple different things, but nothing is doing it.

    Thanks!

    In this code you have a little mistake
    you get $terms = get_terms( 'product_cat', $args );
    but then you do if ( $product_categories )
    Change it to if ( $terms ) and it will be working

    You should put the number of desired categories in between the “”.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WooCommerce [product_categories number=""]’ is closed to new replies.