Pawan Kumawat

How To Change The Number Of Products On Shop Page In WooCommerce

In WooCommerce, the number of products displayed on the shop page is controlled by settings in your WordPress dashboard.
There are some common methods to change the number of products on the shop page:

 

**Method 1: Using WooCommerce Settings**
1. Log in to your WordPress admin dashboard.
2. Navigate to “WooCommerce” > “Settings.”
3. Click on the “Products” tab at the top.
4. Under the “Display” section, find the option labeled “Shop Page Display.”
5. Here, you can adjust the “Shop page” value to set the number of products displayed per page. You can choose from options like 12, 24, 36, or a custom number.

Remember to save your changes by clicking the “Save changes” button at the bottom of the page.

 

**Method 2: Using Functions.php (for Customization)**
If you want more control and wish to customize the number of products displayed beyond the options provided in the settings, you can use the `pre_get_posts` action hook in your theme’s `functions.php` file.

1. Log in to your WordPress admin dashboard.
2. Go to “Appearance” > “Theme Editor.”
3. Look for the “functions.php” file in the right-hand side list of theme files.
4. Add the following code at the end of the `functions.php` file:

function custom_woocommerce_products_per_page($query) {
    if (is_shop()) {
        $query->set('posts_per_page', 20); // Change 20 to your desired number of products per page
    }
}
add_action('pre_get_posts', 'custom_woocommerce_products_per_page');

Replace `20` with the desired number of products you want to display per page.

 

**Method 3: Using a Shortcode**
You can override the default shop page settings using a shortcode. For instance, if you want to display 8 products per page, you can add the following shortcode to the shop page content or any page where you want to display the products:

[products per_page="8"]

Change the value to your desired number of products per page.

 

**Method 4: Using a Custom Plugin**
You can achieve this by using a custom plugin that allows you to control various WooCommerce settings. One such plugin is “WooCommerce Customizer,” which enables you to customize different aspects of your WooCommerce store, including the number of products displayed per page.

Here’s how to use the “WooCommerce Customizer” plugin:
1. Install and activate the “WooCommerce Customizer” plugin through the WordPress admin dashboard.
2. Go to “WooCommerce” > “Customizer.”
3. Click on the “Products” tab.
4. Adjust the “Products per page” setting to your desired number.
5. Save the changes.

 

**Method 5: Using Custom Functions.php (with `loop_shop_per_page`)**
You can use the `loop_shop_per_page` filter in your theme’s `functions.php` file to modify the number of products displayed per page. Here’s how:

function custom_woocommerce_products_per_page($cols) {
    return 12; // Change 12 to your desired number of products per page
}
add_filter('loop_shop_per_page', 'custom_woocommerce_products_per_page');

Change `12` to your desired number of products you want to display per page.

 

Categories

Related Blogs

Adding Sidebar In WordPress Theme

Adding a sidebar to a WordPress theme involves modifying the theme files and registering a new sidebar area using WordPress functions. Below are the general steps to add a sidebar in WordPress themes:

Calculate distance between 2 address using latitude and longitude

To calculate the distance between two locations using their latitude and longitude coordinates, you can use the Haversine formula. The Haversine formula is commonly used to calculate the great-circle distance between two points on the surface of a sphere (such as the Earth) given their latitude and longitude.

WooCommerce: Check if Product ID is in the Cart

To check if a specific product ID is in the cart in WooCommerce, you can use the `woocommerce_before_cart` action hook, which is fired before the cart page is displayed. Here’s how you can achieve this: