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

Fitler request: TaxJar_Order_Record::should_sync() #261

Open
devinsays opened this issue Aug 9, 2024 · 1 comment
Open

Fitler request: TaxJar_Order_Record::should_sync() #261

devinsays opened this issue Aug 9, 2024 · 1 comment

Comments

@devinsays
Copy link

We'd like to prevent TaxJar sync for any orders created more than 180 days ago. We're making this work by using the taxjar_order_sync_data filter, but it would be great to have a filter directly on the should_sync method.

Here's the code workaround we implemented to better explain the use case:

add_filter( 'taxjar_order_sync_data', [ $this, 'maybe_prevent_old_order_sync' ], 10, 2 );
/**
	 * When TaxJar syncs orders to record tax, we don't want it syncing orders that are
	 * more than 180 days old. At this point, tax should have already been recorded.
	 *
	 * This hooks into the taxjar_order_sync_data filter, which is called when building
	 * the data that TaxJar will use to sync the order; if it's missing something critical,
	 * such as destination country, it will not sync the order.
	 *
	 * @see taxjar-simplified-taxes-for-woocommerce/includes/class-taxjar-order-record.php
	 * @see \TaxJar_Order_Record::should_sync(), \TaxJar_Order_Record::get_data_from_object()
	 *
	 * @param array     $taxjar_order_data
	 * @param \WC_Order $order
	 * @return array
	 */
	public function maybe_prevent_old_order_sync( $taxjar_order_data, $order ) {
		$days_old = absint( ( time() - strtotime( $order->get_date_created() ) ) / DAY_IN_SECONDS );
		if ( $days_old > 180 ) {
			// Set to blank value to trigger the should_sync check to return false.
			$taxjar_order_data['to_country'] = '';
		}

		return $taxjar_order_data;
	}

}
@ahumulescu
Copy link
Collaborator

Hello,

Thank you for reaching out to us!

Have you also had a look at the 'taxjar_should_sync_order' filter?

Here are some references:
https://github.com/taxjar/taxjar-woocommerce-plugin/blob/master/includes/abstract-class-taxjar-record.php#L175
https://github.com/taxjar/taxjar-woocommerce-plugin/blob/master/includes/class-wc-taxjar-transaction-sync.php#L232

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

2 participants