taxjar / taxjar-woocommerce-plugin

WooCommerce Sales Tax Plugin by TaxJar
http://www.taxjar.com/woocommerce-sales-tax-plugin/
GNU General Public License v2.0
28 stars 29 forks source link

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

Open contemplate opened 11 months ago

contemplate commented 11 months ago

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 commented 11 months ago

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';