WooCommerce Tips & Tricks

Topics focus on Web Developments, Programming, Database, Digital Marketing Tutorials, Code Snippets, SEO, Social Media Marketing and Inspirational articles.

WooCommerce Tips & Tricks

WooCommerce Tips & Tricks

WooCommerce Tips & Tricks

Here, I wrote this article about woocommerce some tips & tricks which is helpful to customize some woocommerce store when client requirement is something different. So It will help you to make changes in code as per requirement in woocommerce.

How to display no. of products in one line

1
2
global $woocommerce_loop;
$woocommerce_loop['columns'] = 2;

How to display no. of products on shop page

1
add_filter('loop_shop_per_page', create_function('$cols', 'return 8;'))

How to display product from specific category in theme

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
	$args = array('post_type' => 'product',  'taxonomy' => 'product_cat', 'term'=>'latest product', 'showposts'=>'3'); 
	$loop = new WP_Query( $args );
?>
	<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
		<li>
			<div class="product-box">
			<?php the_post_thumbnail( array (330, 188) );?>
				<span class="product-detail">
				<?php echo $product->get_price_html(); ?>
					<a href="<?php the_permalink(); ?>" class="detail-btn">Details</a>
				</span>
			</div>
		<?php the_title(); ?>
		</li>
	<?php endwhile;?>

WooCommerce comes with several shortcodes which can be used to insert content inside posts and pages. The following shortcodes are inserted into pages upon installation and therefore shouldn’t need to be used anywhere else.

[woocommerce_cart] – shows the cart page
[woocommerce_checkout] – shows the checkout page
[woocommerce_pay] – shows the checkout pay page
[woocommerce_thankyou] – shows the order received page
[woocommerce_order_tracking] – shows the order tracking form
[woocommerce_my_account] – shows the user account page
[woocommerce_edit_address] – shows the user account edit address page
[woocommerce_view_order] – shows the user account view order page
[woocommerce_lost_password] – shows the lost password page

You can add shortcodes to a post or page easily via the shortcode shortcut button in the post editor.

Recent products
Lists recent products – useful on the homepage. The per page limits the amount of recent products shown, and the columns attribute controls how many columns wide the products should be before wrapping.

[recent_products per_page=”12″ columns=”4″]

Featured Products
Works exactly the same as recent products but displays products which have been set as “featured”.

[featured_products per_page=”12″ columns=”4″]

Product
Show a single product by ID or SKU.

[product id=”101″]
[product sku=”FOO”]

Products
Show multiple products by ID or SKU. Make note of the plural ‘products’.

[products ids=”1, 2, 3, 4, 5″]
[products skus=”foo, bar, baz” orderby=”date” order=”desc”]

Add to cart
Show the price and add to cart button of a single product by ID.

[add_to_cart id=”101″]

Add to cart URL
Echo the URL on the add to cart button of a single product by ID.

[add_to_cart_url id=”99″]

Product page
Show a full single product page by ID or SKU.

[product_page id=”101″]
[product_page sku=”FOO”]

Product Category
Show multiple products in a category by slug.
Args:
array( ‘per_page’ => ’12’, ‘columns’ => ‘4’, ‘orderby’ => ‘title’, ‘order’ => ‘asc’, ‘category’ => ” )

[product_category category=”foo”]

Product Categories
Display product categories loop
Args:
array( ‘number’ => ‘null’, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘columns’ => ‘4’, ‘hide_empty’ => ‘1’, ‘parent’ => ” )

[product_categories number=”12″ parent=”0″]
Set the parent parameter to 0 to only display top level categories.

Sale Products
List all products on sale
Args:
array( ‘per_page’ => ’12’, ‘columns’ => ‘4’, ‘orderby’ => ‘title’, ‘order’ => ‘asc’ )

[sale_products per_page=”12″]

Best Selling Products
List best selling products on sale
Args:
array( ‘per_page’ => ’12’, ‘columns’ => ‘4’ )

[best_selling_products per_page=”12″]

Top Rated Products
List top rated products on sale
Args:
array( ‘per_page’ => ’12’, ‘columns’ => ‘4’, ‘orderby’ => ‘title’, ‘order’ => ‘asc’ )

[top_rated_products per_page=”12″]

To set number of products in paging woocommerce
add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 4;’ ), 20 ); in functions .php

Add comment


 

Pin It on Pinterest

Share This