WP E-Commerce displays all the products from all the categories in the default products page which uses the template file: wpsc-products_page.php for displaying. There are situations when we have product categories, under each category we have different products. Now we have to display all the products grouped by product-categories. Like:
Product-Category#1 โ Product #1 โ Product #2 โ Product #3 Product-Category#2 โ Product #4 โ Product #5 Product-Category#3 โ Product #6 โ Product #7 โ Product #8
Solution:
We can achieve this using short-codes provided by wp e-commerce, but then we have to write the shortcode that many number of times as we have number of categories.
[wpsc_products category_id='4'] [wpsc_products category_url_name='test-category'] [wpsc_products category_url_name='test-category' number_per_page='16' sort_order='price' order='desc']
Find a complete list of wp e-commerce category shortcodes with additional arguments
There are some other problems like: we have to create another product page,write the short codes there and keep the default products page intact, else chances are there that the single product page, category page etc. may break or show page not found error.
So another option is to change the default products-page template file( wpsc-products_page.php ) to display products group by categories. This can be done by running multiple loops in the the products page template file. I have used this once and works fine for me. Use this if it suits your requirement. ๐
Steps:
— Open the wpsc-products_page.php file.
— Find the products loop statement in the code.
— Find the products loop end statement.
— Copy the whole block in between while and endwhile for the product loop.
— Then enclose those copied code inside the below mentioned condition.
— Save and check the products page.
Example Code:
term_id; $wpec_term_name = $wpec_categories->name; $wpec_term_slug = $wpec_categories->slug; /* --------- JUST PRODUCT CATEGORY WHICH IS DEFAULT IN WPSC ---------- */ if($wpec_term_slug == 'categories' || $wpec_term_slug == 'product-category') { continue; } /* --------- SET THE PRODUCT QUERY ARGUMENTS ARRAY --------- */ $wpec_args = array( 'post_status' => 'publish', 'post_type' => 'wpsc-product', 'numberposts' => 12, 'showposts' => 12, 'wpsc_product_category' => $wpec_term_slug ); $wpec_categoryProducts = new WP_Query($wpec_args); ?>have_posts()) : $wpec_categoryProducts->the_post(); global $wpsc_custom_meta, $wpsc_variations; $wpsc_custom_meta = new wpsc_custom_meta( get_the_ID() ); $wpsc_variations = new wpsc_variations( get_the_ID() ); /* ======================================================================= */ /* ADDED/MODIFIED CODE -- CHANGED THE PRODUCT LOOP ABOVE TO OUR CUSTOM ONE */ /* ======================================================================= *//* ---------- ------------- Continue code - product display ------------- ---------- *//* ---------- ------------- Continue code - product display(same as previous) ------------- ---------- */
Download the modified wpsc-products_page.php !!
Leave a Reply