I have a lots of products with variations in my woocommerce installation. None of them is preselected as default when user browses to any product page.
Manually, selecting them would be a tedious job. Additionally, new products and variations are imported automatically on daily basis using SQL script.
I would like to have preselected product variation with highest price for any user that browses to any product page which has variable product.
How to do that?
Here it is an automated solution, that will do the job each time a variable product is called/browse by a customer.
The variable product will be updated with a default variation that has the highest price.
This will be done once only as I set a custom post meta key/value each time a variable product has been updated.
The code:
Code goes in function.php file of your active child theme (active theme).
Tested and works.
Go to the file
woocommerce/templates/single-product/add-to-cart/variable.php
and add the following line:To the function
wc_dropdown_variation_attribute_options()
. This will pre-select the first variant on the product display page.