Filter Hook Request: omnisend_order_data
-
Can you guys help with adding the filter hook omnisend_order_data to
/manager/class-omnisend-manager.php
public static function push_order_to_omnisend( $order_id ) {
if ( ! self::is_setup() ) {
return;
}
$order_object = Omnisend_Order::create( $order_id );
if ( ! $order_object ) {
$message = 'Unable to push Order #' . $order_id . ' to Omnisend. One or more required fields are empty or invalid';
Omnisend_Logger::log( 'warn', 'orders', '', $message );
Omnisend_Sync::mark_order_sync_as_skipped( $order_id );
return;
}
$order_array = Omnisend_Helper::clean_model_from_empty_fields( $order_object );
// Add filter hook here
$order_array = apply_filters( 'omnisend_order_data', $order_array );
$verbs_to_try = Omnisend_Sync::was_order_synced_before( $order_id ) ? array( self::VERB_PUT ) : array( self::VERB_POST, self::VERB_PUT );
foreach ( $verbs_to_try as $verb ) {
$api_url = $verb == self::VERB_POST ? OMNISEND_API_URL . '/v3/orders' : OMNISEND_API_URL . '/v3/orders/' . $order_id;
$curl_result = Omnisend_Helper::omnisend_api( $api_url, $verb, $order_array );
if ( $curl_result['code'] >= 200 && $curl_result['code'] < 300 ) {
Omnisend_Logger::log( 'info', 'orders', $api_url, "Order #$order_id was successfully pushed to Omnisend." );
Omnisend_Sync_Stats_Repository::count_item( 'orders' );
Omnisend_Sync::mark_order_sync_as_synced( $order_id );
Omnisend_Contact_Resolver::update_by_email( $order_object->email );
return;
}
if ( in_array( $curl_result['code'], self::HTTP_STATUS_CODES_TO_RETRY_POST_IN_PUT ) ) {
Omnisend_Logger::log( 'warn', 'orders', $api_url, 'Unable to push order #' . $order_id . ' to Omnisend.' . $curl_result['response'] );
continue;
}
if ( $curl_result['code'] == 403 ) {
Omnisend_Logger::log( 'warn', 'orders', $api_url, "Unable to push order #$order_id to Omnisend. You don't have rights to push orders." );
break;
}
Omnisend_Logger::log( 'warn', 'orders', $api_url, "Unable to push order #$order_id to Omnisend. May be server error. " . $curl_result['response'] );
break;
}
Omnisend_Sync::mark_order_sync_as_error( $order_id );
}Just add the
// Add filter hook here
$order_array = apply_filters( ‘omnisend_order_data’, $order_array );to the function push_order_to_omnisend in class-omnisend-manager.php.
So we can make changes to the order data sent to omnisend like for example, the order currency and We need to adjust the order data sent to Omnisend, specifically the order currency and amount. Currently, our store accepts multiple currencies, so the data we’re sending to Omnisend includes various currencies. However, the Omnisend dashboard doesn’t support multiple currencies and treats all amounts as if they were in our default currency. To resolve this, I’d like to manually set the order currency to USD and convert all order amounts to USD before sending them to Omnisend.
- You must be logged in to reply to this topic.