Programmatically Updating Wholesale Prices
-
Hello Support Team,
I am currently working on integrating a bulk price update feature into my WooCommerce store, which needs to update both regular and wholesale prices across all products. While I have been successful in updating the regular prices, I’m facing challenges with updating the wholesale prices, which are managed by your WooCommerce Tiered Price Table plugin.
Here’s a brief overview of what I am trying to accomplish:
- I have an admin page where I can input a percentage by which to increase or decrease prices.
- I want this percentage change to apply to both regular and wholesale prices for all products.
- I am using a batch processing approach to avoid server timeouts for large numbers of products.
So far, I’ve attempted to use your plugin’s provided classes and methods (
\TierPricingTable\PriceManager::getPricingRule
) to retrieve and update the pricing rules. However, my AJAX request to trigger this update results in a “critical error” message without further specifics.Could you provide guidance or documentation on the correct method to programmatically update wholesale prices via PHP? Specifically, I am looking for the best way to retrieve the current wholesale pricing rules, apply a percentage-based adjustment, and then save these updated prices back to the system.
For your reference, here is the snippet of code where I’m attempting to update the wholesale prices:
// Update wholesale prices if the plugin is active and the product has wholesale prices if (class_exists('\TierPricingTable\PriceManager')) { $pricingRule = \TierPricingTable\PriceManager::getPricingRule($product_id); if ($pricingRule && !empty($pricingRule->getRules())) { $rules = $pricingRule->getRules(); $updated_rules = []; foreach ($rules as $quantity => $price) { $updated_price = ceil($price * $increase_factor * 4) / 4; // rounding up to the nearest 0.25 $updated_rules[$quantity] = $updated_price; } $pricingRule->setRules($updated_rules); $pricingRule->save(); } }
If there are any known issues or additional steps required for this process to work correctly, your assistance would be greatly appreciated. Furthermore, if there are specific log files or debugging methods that could reveal more detailed error messages from the plugin, that information would be very helpful as well.
Thank you for your time and assistance.
Best regards,
Alex
The page I need help with: [log in to see the link]
- The topic ‘Programmatically Updating Wholesale Prices’ is closed to new replies.