Tag - woocommerce

Woocommerce Custom Sidebar on Shop Page (Without using a plugin)
Fix Blurry Product Thumbnail Images in the Divi Shop Module

Woocommerce Custom Sidebar on Shop Page (Without using a plugin)

After working with Woocommerce recently, I discovered that out of the box, Woocommerce displays the main blog sidebar on the shop pages.

Since the main WordPress sidebar contains blog-related widgets by default, this is clearly far from ideal.

I wanted instead for the Woocommerce shop page to have it’s own sidebar, with widgets related to searching and filtering products, not posts.

After digging through the code looking for a clean solution, I found that the solution is easy, and it’s as clean as copying a single template file and making a minor edit.

1. Create your new Widget Area

In your website’s filesystem (using your OS’s file explorer if it’s local to your machine, or via SFTP if it’s a remote webserver), navigate to your theme’s directory (/wp-content/themes/THEMENAME/) and edit the functions.php file.

At the end of the file, add the following code:

function custom_widgets_init() {
			'name'          => esc_html__( 'Shop Sidebar', 'sirius' ),
			'id'            => 'sidebar-shop',
			'description'   => esc_html__( 'Add widgets here.', 'sirius' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h4>',
			'after_title'   => '</h4>',
add_action( 'widgets_init', 'custom_widgets_init' );

If you already have a function attached to the widgets_init action, you can just add the call to register_sidebar into it.

2. Add widgets to your new widget area

Drag some widgets into your new widget area. Here are a few relevant Woocommerce widgets you might find appropriate:

  • Product Search
  • Filter Products by Attribute
  • Product Categories
  • Product Tag Cloud
  • Products By Rating
  • Recent Viewed Products

Adding widgets to the widget area


3. Create a custom shop sidebar template

Now we’re ready to create the template file which will output the new sidebar on the frontend of your website.

In your website’s filesystem (using your OS’s file explorer if it’s local to your machine, or via SFTP if it’s a remote webserver), navigate to your theme’s directory (/wp-content/themes/THEMENAME/) and copy the sidebar.php file to sidebar-shop.php

Edit the new sidebar-shop.php template using your favourite text editor and change any references to ‘sidebar-1’ to ‘sidebar-shop’

Here is the content from my sidebar-shop.php file.

 * The sidebar containing the main widget area
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 * @package Sirius
if ( ! is_active_sidebar( 'sidebar-shop' ) ) {
<aside id="secondary" class="widget-area">
	<?php dynamic_sidebar( 'sidebar-shop' ); ?>
</aside><!-- #secondary -->

And you’re done!

Now when you visit the shop page on the frontend of your website, you should see your shop sidebar instead of the main sidebar which is displayed when visiting the rest of your site.

If that was helpful, I’d really appreciate you taking the time to share this post on social media. You may also like to check out some of my other Woocommerce and WordPress related posts.

Fix Blurry Product Thumbnail Images in the Divi Shop Module

If you have built an eCommerce store using Woocommerce and Divi, you will probably know how powerful these plugins are and just how rapidly you can build a professional, SEO optimised storefront almost entirely in the browser with a minimal amount of coding.

Having said that, there are few shortcomings in Divi, particularly with regards to getting things right for SEO.

One such issue being the low resolution thumbnail images in the Divi shop module.

Blurry, Low Resolution Images

The product photos in the grid listing of the Divi shop module are rendered at just 150px by 150px byt the WordPress Thumbnail function. This means that they have to be scaled up by the browser. The net result being blurry photos.

This might be okay if you have 5 products per row, but if you decide to change the module to show 3 products per row, then those 150px images have to be scaled up to 320px wide by the browser. I’m sure that you’re already aware that scaling up an image to more than double it’s original size is obviously going to reduce image quality, quite a lot. The end result is blurry product photos. Not good if you want a nice looking website or online store:

Blurry Product Photos


Increasing Image Resolution

To correct this problem, we will have to tell WordPress (or Divi) to output the images at a higher resolution than 150px. After some digging through the Divi code to trace how the image tags are generated, I found a clean way to set image sizes for product images in archive listings, using WordPress filters.

To increase the size of your shop’s product images, add the following code to the functions.php file within your theme:

function theme_setup() {
function theme_size_of_product_thumb($u)
return array(332, 332,true);
add_filter('single_product_archive_thumbnail_size', 'theme_size_of_product_thumb');
add_action( 'after_setup_theme', 'theme_setup' );

After you have added the code, refresh the frontend of your website and the product images should appear sharp:

Sharp High Resolution Product Photos


In the example here, I used 332×332 for the image dimensions as that was sufficient for the 3 items per row I was displaying.

If your images are displayed larger than 332×332, perhaps if you are showing fewer than 3 items per row, then you might want to render your images at a higher resolution.

Bear in mind though that larger images means larger image filesizes, which in turn leads to slower page load times. As long as you don’t go huge, this shouldn’t be too much of an issue.

Copyright © 2018. Created by Hayden Kibble.