Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › WP eStore Tweaks › estore- custom product display grouped by category
- This topic has 3 replies, 2 voices, and was last updated 9 years, 5 months ago by admin.
-
AuthorPosts
-
May 2, 2015 at 7:24 pm #12584kayjayoneMember
Trying to do a custom product display using the following…
[wp_eStore_product_details id=1 info=”name”]
[wp_eStore_product_details id=1 info=”description”]
[wp_eStore_product_details id=1 info=”price”]
[wp_eStore_product_details id=1 info=”available_copies”]
[wp_eStore_add_to_cart id=1]
Because we only want the cart button to show if the user is logged in. We would like to group the products by category for listing, how might this be possible?
Output would be…
Category1 Name
Product1- image, name, description, price and add to cart button if user is logged in
Product2- same
Category2 Name
etc.
Thank you for your help.
May 3, 2015 at 12:12 am #69853adminKeymasterWhich part are you having trouble with? You should be able to enter your category name on the page then below it, put the shortcode for all the products.
If you have a lot of products, it is best to use the “show all products from a category” shortcode. See the shortcode guide for explanation on that shortcode:
https://www.tipsandtricks-hq.com/ecommerce/wp-estore-shortcodes-and-functions-reference-460
May 3, 2015 at 12:46 am #69854kayjayoneMemberThank you for your quick reply! I’m unable to use the show all products from a category shortcode, although that is what I want to display, because created a custom product display to format the output further and display the add to cart button conditionally for this implementation (code below). I’d like to put a loop around the code below to loop through all categories and display all products in each category. Thank you for your help!
--loop all categories--
<h2>Category Name</h2>
--loop all products within category--
<div class="prodbox">
<div class="prodimg"><img src="<?php echo do_shortcode('[wp_eStore_product_details id=41 info="thumbnail_url"]')?>" alt="Tomato Empire" /></div>
<h3><?php echo do_shortcode('[wp_eStore_product_details id=41 info="name"]')?></h3>
<div class="prodinfo">
<div class="proddesc"><?php echo do_shortcode('[wp_eStore_product_details id=41 info="description"]')?></div>
<div class="prodavail">Available Quantity: <?php echo do_shortcode('[wp_eStore_product_details id=41 info="available_copies"]')?> Pounds</div>
<div class="largetext">Price per Pound: $<?php echo do_shortcode('[wp_eStore_product_details id=41 info="price"]')?></div>
<?php if (wp_emember_is_member_logged_in()) { echo do_shortcode('[wp_eStore_add_to_cart id=41]'); }?>
</div><!--prodinfo-->
</div><!--prodbox-->
--end loops--
May 4, 2015 at 1:50 am #69855adminKeymasterHere is an example loop code:
global $wpdb;
$cat_table_name = WP_ESTORE_CATEGORY_TABLE_NAME;
$cat_prod_rel_table_name = WP_ESTORE_CATEGORY_RELATIONS_TABLE_NAME;
$products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
$resultset = $wpdb->get_results("SELECT * FROM $cat_table_name ORDER BY cat_id ASC", OBJECT);
foreach ($resultset as $row)
{
$cat_id = $row->cat_id
$category_products = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name where cat_id=$cat_id ORDER BY prod_id ASC", OBJECT);
foreach ($category_products as $item_row)
{
$prod_id = $item_row->prod_id;
//TODO - Show this product's info
}
} -
AuthorPosts
- You must be logged in to reply to this topic.