Every online store or shopping website dealing with Digital products and using WooCommerce needs to manage the “Downloads” section of its customers in a hassle-free manner. There is a variety of columns that are displayed in the Downloads section, including Product details, License Key, Expiry, and remaining Downloads. But what would you do if there is a need to remove or add more columns or modify the existing ones in that download section? Sometimes there would be a requirement to showcase some additional information about an existing downloaded product.
You would be happy to know that doing all these things on your digital store is pretty easy. In this discussion, we will introduce you to some quick tips and easy tricks to get all these things done in a very uncomplicated way.
Note that before carrying out any of these operations, it is strictly recommended to install and activate a child theme. This is due to the fact that whenever the theme is updated, all of your changes will be erased immediately.
How to Remove a Column
Let’s have a close look at the Downloads section of a WooCommerce store.
Suppose that the Downloads remaining column is unnecessary, and you want to remove it without getting into any messes.
To remove a column from the Downloads section of any WooCommerce store, you only need to access the functions.php file located in the themes folder and add the following code to its bottom.
// To remove unwanted column
function wpmz_remove_woocommerce_account_downloads_columns($columns) {
if ( isset( $columns['download-remaining'] ) ) {
unset( $columns['download-remaining'] );
}
return $columns;
}
add_filter('woocommerce_account_downloads_columns', 'wpmz_remove_woocommerce_account_downloads_columns');
After that, you have to put the Column id of the column which you want to remove into the if( ) section. Every column in the Download section has a unique Column id. To find out the Column id of a particular column you need to take the help of inspect element feature of your browser. Like in this case the Column id is “download-remaining“.
After appending the above code in the functions.php file, save it and reload the page. You will notice that the Downloads remaining column has vanished now.
How to Add a Column and its Values
Sometimes there are requirements to add a new column in the Downloads section, and believe me, doing that is a little tricky task. If you want to extend the number of columns in the Downloads section, then just follow these simple steps to get it done in a few minutes.
In this case, we are going to add a new column to display the Order ID of all the downloaded products.
This can be easily done by adding the below code to the functions.php file. (‘Order ID’) is the column name that will be displayed on the front end, and [‘order-id’] is the Column id. You can modify these as per your requirements.
// To add a column
function wpmz_add_woocommerce_account_downloads_columns($columns) {
$columns['order-id'] = esc_html( 'Order ID' );
return $columns;
}
add_filter('woocommerce_account_downloads_columns', 'wpmz_add_woocommerce_account_downloads_columns');
Reload the page to see the changes. You will notice that the Order ID column has been successfully added in the Download section table.
As of now, the new column has been placed in the download section, but it does not have any Order IDs for any of the downloads. Without any Order IDs, it is useless.
In order to display the Order IDs for all the respective downloads, we need to simply add the below code in the same functions.php file. You can easily find the [ ‘ order_id ‘ ] in the download parameter passed in the function.
// To add content in the above column
function wpmz_woocommerce_account_downloads_column_order_id($download) {
if ( isset( $download['order_id'] ) ) {
echo $download['order_id'];
}
}
add_action('woocommerce_account_downloads_column_order-id', 'wpmz_woocommerce_account_downloads_column_order_id');
Immediately after adding the lines of code to the functions.php file, the Order IDs would appear in the column.
In the same way, you can find and display several other useful information using the download parameter passed in the function. Some of them are:
- download_url
- product_id
- product_name
- download_name
- order_key
- access_expires
These configuration will be quite helpful in further customizations after you had built your WooCommerce store with Divi.
I hope that after reading this article, you’ll be able to quickly understand how to extend and reduce the number of columns in the Downloads section of a WooCommerce store. As a result, you might be able to alter the column layout of the Downloads section of your WooCommerce store to meet up your requirements.
0 Comments