Hustle In Progress

Bulk update WooCommerce Measurement Price Calculator settings

Recently I was tasked with adding around 180 products to a WooCommerce store that uses the WooCommerce Measurement Price Calculator plugin. I quickly found out it’s impossible to globally update the settings. You have to go into each product, find the right tab in the metabox and update the settings accordingly.

Of course, I turned to the internet to find a solution that would help me bulk update—but there wasn’t really anything useful. However, I did find this in their documentation:

You can import and export products with measurement settings with the WooCommerce Product CSV Suite, but creating new measurement products via import is not really possible. The measurement data is stored as serialized meta, so while exporting and then re-importing existing products works just fine, creating new measurement products via an import is not ideal. New products should be configured in the WooCommerce admin.

Bummer! I needed a solution ASAP, you know project deadlines and stuff 🤓

So, I turned to jQuery to set up all the settings per product that I needed. This was perfect, because I still needed to go into every single product anyway to update photos and such.

So, I created a script that initialises on the product edit page, inputs the settinngs, and when the product gets updated those values will be saved in the database. If you have specific settings that are different per product, this will probably not work and you still need to do a bit of manual work 😭. However, you can still update the settings that are the same on every product and save a lot of time.

function bulk_update_woo_measurement_price_calc(){
 ?>
    <script>
    jQuery(document).ready(function($) {
        function bulk_edit_woo_price_measurement() {
            $('select[name="_measurement_price_calculator"]  option[value="area"]').prop("selected", true );
            $("#_measurement_area_pricing").prop("checked", true);
            $('input[name="_measurement_area_pricing_label"]').val("m<sup>2</sup>");
            $("#_measurement_area_pricing_calculator_enabled").prop("checked", true);
            $('input[name="_measurement_area_label"]').val("Voer benodigde vierkante meters in:");
        }

        if ($("body.post-type-product").length > 0) {
            bulk_edit_woo_price_measurement();
        }
    });
    </script>
 <?php
}
add_action( 'admin_print_scripts', 'bulk_update_woo_measurement_price_calc', 999 );

Add comment

Chris Schwartze

Hey, what’s up! I’m Chris and I’m based in Enschede, The Netherlands. I have a long history of music production, marketing, web design, and development.

facebook advertising ebook

scrap · noun · a small piece of something that is left over after the greater part has been used.

beeketing-ebook-2

Check out Urban Masterclass—online platform for hiphop/R&B artists.

Join over 2480+ hustlers

Get actionable content in your inbox

Get email notifications for new posts