• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

[DEVELOPER NEEDED] Create function to update Woocommerce price of all variations at once

krdza93

New member
May 9, 2022
10
2
3
I need someone to do this and I will pay, or someone who can help me do it if he already has something similar that works.

So I am using this plugin to have measurement-based product calculations as I am selling wallpapers

There are 4 different variations of each wallapaper, based on the material.
Each material has its own price, which is currently set per product on variations.In catalog there are about 4.000 products, which means 16.000 variations, so you know where is the problem with updating this manually - will take ages.

I need functionality to enter the price per variation and on submit to update all variations.

Example:

Paper Wallpaper costs 6eur per sq m and I want to update the price to 7eur per sq m on all products, with Paper Wallpaper variation, while keeping others as they are (Like, keeping the price of 10eur for Glued Wallpaper)

Can someone help me with this one, or send an estimate, I would pay for this, as I cannot do it manually anymore, since catalog is constantly growing.
 
You might wanna try something like this as a function in your functions.php and call it whenever you want to change the price.
This is a raw start for anyone who wants to implement it
It can also be beautified with a form and dynamic product price to be updated from dashboard.
PHP:
function update_price() {
$regular_price = 7;

if( $post->post_type == 'product' ) $product = wc_get_product( $post->ID ); // Only for product post type

// Only for variable products
	if( $product->is_type('variable') && $product->get_name() == 'Paper Wallpaper'){
		
		foreach( $product->get_available_variations() as $variation_values ){
			$variation_id = $variation_values['variation_id']; // variation id
			// Updating active price and regular price
			update_post_meta( $variation_id, '_regular_price', $regular_price );
			update_post_meta( $variation_id, '_price', $regular_price );
			wc_delete_product_transients( $variation_id ); // Clear/refresh the variation cache
		}
		wc_delete_product_transients( $post->ID ); // Clear/refresh the variable product cache
}
}

If you Paper Walpaper is set as variation value then the code slightly changes to make the check of variation name instead of product name
 
You might wanna try something like this as a function in your functions.php and call it whenever you want to change the price.
This is a raw start for anyone who wants to implement it
It can also be beautified with a form and dynamic product price to be updated from dashboard.
PHP:
function update_price() {
$regular_price = 7;

if( $post->post_type == 'product' ) $product = wc_get_product( $post->ID ); // Only for product post type

// Only for variable products
    if( $product->is_type('variable') && $product->get_name() == 'Paper Wallpaper'){
       
        foreach( $product->get_available_variations() as $variation_values ){
            $variation_id = $variation_values['variation_id']; // variation id
            // Updating active price and regular price
            update_post_meta( $variation_id, '_regular_price', $regular_price );
            update_post_meta( $variation_id, '_price', $regular_price );
            wc_delete_product_transients( $variation_id ); // Clear/refresh the variation cache
        }
        wc_delete_product_transients( $post->ID ); // Clear/refresh the variable product cache
}
}
Thanks, will try this one - how do I create a form and a dashboard to update it in future? I guess my PHP timeout limit must be increased due to a lot of processes ?
 

You may try it first without changing any limits. If error then you can slightly increase timeout limit

Edit: I misread your first requirements and it seems that Paper wallpaper is a variation of a product. So code needs a little refactoring to make the check on variation name instead of product name
 
Last edited:
you can also give this a try "WP Sheet Editor" it will make excel looking sheet of your products so you can change anything just from a live excel sheet.
This seems pretty straight forward approach, But if you still need to do it dynamically you can hire me🙃
 
Last edited:
I need someone to do this and I will pay, or someone who can help me do it if he already has something similar that works.

So I am using this plugin to have measurement-based product calculations as I am selling wallpapers

There are 4 different variations of each wallapaper, based on the material.
Each material has its own price, which is currently set per product on variations.In catalog there are about 4.000 products, which means 16.000 variations, so you know where is the problem with updating this manually - will take ages.

I need functionality to enter the price per variation and on submit to update all variations.

Example:

Paper Wallpaper costs 6eur per sq m and I want to update the price to 7eur per sq m on all products, with Paper Wallpaper variation, while keeping others as they are (Like, keeping the price of 10eur for Glued Wallpaper)

Can someone help me with this one, or send an estimate, I would pay for this, as I cannot do it manually anymore, since catalog is constantly growing.
I generally use WP Sheet Editor for such Tasks...It's Automated too... Just Bulk Variations Create/Copy and Let it Run
 
  • Like
Reactions: Simbaa
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock