Skip to content

Fitler request: TaxJar_Order_Record::should_sync() #261

@devinsays

Description

@devinsays

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

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions