Search code examples
phpwordpresswoocommerceconstantsproduct-variations

Change the amount of variations displayed in Woocommerce


By default Woocommerce loads 50 variations per run.

Searching the web, I found a line of code to be entered in the functions.php file, of my active child theme.

define( ‘WC_MAX_LINKED_VARIATIONS’, 150);

After copying it in the functions.php file, I did not get changes and the 50 variations are still being loaded and not 150 as I indicated in the line of code.

This is the functions.php file:

<?php

//CARGA EL STYLE.CSS DEL TEMA PADRE EN EL TEMA HIJO

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}

//Incremento de las variaciones en Woocommerce  
define( ‘WC_MAX_LINKED_VARIATIONS’, 150);

?>

Solution

  • Just tested it on my local machine and found that define( 'WC_MAX_LINKED_VARIATIONS', 150 ); can be used either in the functions.php or wp-config.php.

    It is not working for you because WC_MAX_LINKED_VARIATIONS is not properly enclosed by the single quote '', instead it is enclosed by apostrophe ‘’:

    • Incorrect: define( ‘WC_MAX_LINKED_VARIATIONS’, 150 );
    • Correct: define( 'WC_MAX_LINKED_VARIATIONS', 150 );

    After making above correction, you can use this constant in any of the following ways:

    1. Either put the correct code in your functions.php file;
    2. Or completely remove it from your functions.php file and add it in your wp-config.php file

    It should work for you.

    WARNING

    1. If you are going to increase the limit, be sure your server/hosting can handle the increased limit as it is resource intensive task.
    2. If your data is not saving, it might be a server/hosting configuration issue as stated in the following WooCommerce documentation.

    Problems with large amounts of data not saving (variations, rates etc) .