Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating old WooCommerce Subscriptions so renewals use new tax class? #247

Open
contemplate opened this issue Jul 26, 2023 · 1 comment
Open

Comments

@contemplate
Copy link

We recently added a new tax class in WooCommerce "Digital Goods - 31000" to all of our virtual subscription products. However we already had 20k+ active subscriptions that we don't believe are sending that tax class on renewals (at least according to TaxJar support and reviewing our exemptions coming in). What is the process for updating these old subscriptions? Use the Recalculate button on each subscription? Add a custom code snippet? Add/Edit a records in the database?

I did look up old subscriptions and in the wp_post_meta I don't see this record: _taxjar_tax_result
However when I press Recalculate on the Subscription the record then appears. Are we suppose to do this for all old subscriptions? What about the Parent Orders?

Actually looks like I could perhaps use a plugin like this to recalculate totals (forked from the original with updated code):
https://github.com/SatelliteWP/woocommerce-subscriptions-recalculate-totals

Or simply run through all subscriptions and run this:
$subscription->calculate_totals(); $subscription->save();

Just needing confirmation on direction here. Thanks!

@contemplate
Copy link
Author

Ok after doing some extensive testing I found the Recalculate button on Subscriptions does NOT update the tax class so renewal orders start sending the proper tax class. The value that needs to be updated is: _tax_class in the wp_woocommerce_order_itemmeta table.

In our case all order line items with "Membership" in the name needed to be updated with the digital-goods-31000 tax class. Here are the queries that worked for us. These are merely examples and should not be used unless you know what you are doing.

SELECT latest 5k tax class records for "membership" line items:
SELECT oim.meta_value, oim.meta_key, oim.order_item_id, oi.order_item_name, oi.order_item_type, oi.order_id FROM wp_woocommerce_order_itemmeta as oim INNER JOIN (SELECT * from wp_woocommerce_order_items WHERE order_item_name LIKE '%Membership%' AND order_item_type = 'line_item' order by order_id DESC limit 0, 5000) as oi ON oim.order_item_id = oi.order_item_id WHERE oim.meta_key = '_tax_class';

UPDATE latest 5k tax class records for "membership" line items:
UPDATE wp_woocommerce_order_itemmeta as oim INNER JOIN (SELECT * from wp_woocommerce_order_items WHERE order_item_name LIKE '%Membership%' AND order_item_type = 'line_item' order by order_id DESC limit 0, 5000) as oi ON oim.order_item_id = oi.order_item_id SET oim.meta_value = 'digital-goods-31000' WHERE oim.meta_key = '_tax_class';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant