Now, you can add custom columns to your Product Variation Table. Here is a quick guide on how you can add custom columns.
Note:
The support for adding a custom column is available from the following plugin versions.
(***You have to install and activate the following plugins to add custom columns)
Product Variation Table For WooCommerce – PVT – Version 1.4.13
Product Variation Table For WooCommerce – PVT PRO – Version 1.4.7
Important:
Once you have added a custom column, please refresh the table columns with the option under the settings. Here is a screenshot of the option:
You can add columns with both static and dynamic data.
Adding a column to your variation table with Static data
Example code to add a column with static data:
add_filter('pvtfw_default_columns', function($default){
// Example of extra column (with `static` table data)
$default['static'] = "on";
return $default;
});
add_filter('pvtfw_columns_labels', function($default){
// Example of extra column (with `static` table data)
$default['static'] = __('Static Column', 'product-variant-table-for-woocommerce');
return $default;
});
add_filter('pvtfw_extra_column_value', function($default, $key, $value, $single_variation){
// Example of extra column (with `static` table data)
if( 'static' === $key ){
$default = 'Static text';
}
return $default;
}, 10, 4);
Adding the above code to your child theme’s functions.php file will add a custom column with static data.
Here is the screenshot of the resulting table:
Adding a column to your variation table with Dynamic data
Example code to add a column with dynamic data:
add_filter('pvtfw_default_columns', function($default){
// Example of extra column (with `dynamic` table data)
$default['status'] = "on";
return $default;
});
add_filter('pvtfw_columns_labels', function($default){
// Example of extra column (with `dynamic` table data)
$default['status'] = __('Status', 'product-variant-table-for-woocommerce');
return $default;
});
add_filter('pvtfw_extra_column_value', function($default, $key, $value, $single_variation){
// Example of extra column (with `dynamic` table data)
if( 'status' === $key ){
$default = $single_variation->get_status();
}
return $default;
}, 10, 4);
Adding the above code to your child theme’s functions.php file will add a custom column with dynamic data.
Here is the screenshot of the resulting table:
In the code example above, we have printed whether the variation is published. All of the variations are enabled so it is listed as published.
Hopefully, you will find the new feature and the example codes helpful 🙂
Was this article helpful?
YesNo