ce_dates_from', '_sale_price_dates_to', 'total_sales', '_tax_status', '_tax_class', '_manage_stock', '_backorders', '_sold_individually', '_weight', '_length', '_width', '_height', '_upsell_ids', '_crosssell_ids', '_purchase_note', '_default_attributes', '_product_attributes', '_virtual', '_downloadable', '_download_limit', '_download_expiry', '_featured', '_downloadable_files', '_wc_rating_count', '_wc_average_rating', '_wc_review_count', '_variation_description', '_thumbnail_id', '_file_paths', '_product_image_gallery', '_product_version', '_wp_old_slug', // Woocommerce orders. // See https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L27 . '_order_key', '_order_currency', // '_billing_first_name', do not sync these as they contain personal data // '_billing_last_name', // '_billing_company', // '_billing_address_1', // '_billing_address_2', '_billing_city', '_billing_state', '_billing_postcode', '_billing_country', // '_billing_email', do not sync these as they contain personal data. // '_billing_phone', // '_shipping_first_name', // '_shipping_last_name', // '_shipping_company', // '_shipping_address_1', // '_shipping_address_2', '_shipping_city', '_shipping_state', '_shipping_postcode', '_shipping_country', '_completed_date', '_paid_date', '_cart_discount', '_cart_discount_tax', '_order_shipping', '_order_shipping_tax', '_order_tax', '_order_total', '_payment_method', '_payment_method_title', // '_transaction_id', do not sync these as they contain personal data. // '_customer_ip_address', // '_customer_user_agent', '_created_via', '_order_version', '_prices_include_tax', '_date_completed', '_date_paid', '_payment_tokens', // '_billing_address_index', do not sync these as they contain personal data. // '_shipping_address_index', '_recorded_sales', '_recorded_coupon_usage_counts', // See https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L539 . '_download_permissions_granted', // See https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L594 . '_order_stock_reduced', '_cart_hash', // Woocommerce order refunds. // See https://github.com/woocommerce/woocommerce/blob/b8a2815ae546c836467008739e7ff5150cb08e93/includes/data-stores/class-wc-order-refund-data-store-cpt.php#L20 . '_order_currency', '_refund_amount', '_refunded_by', '_refund_reason', '_order_shipping', '_order_shipping_tax', '_order_tax', '_order_total', '_order_version', '_prices_include_tax', '_payment_tokens', ); /** * Whitelist for comment meta we are interested to sync. * * @access private * @static * * @var array */ private static $wc_comment_meta_whitelist = array( 'rating', ); /** * Return a list of objects by their type and IDs * * @param string $object_type Object type. * @param array $ids IDs of objects to return. * * @access public * * @return array|object|WP_Error|null */ public function get_objects_by_id( $object_type, $ids ) { switch ( $object_type ) { case 'order_item': return $this->get_order_item_by_ids( $ids ); } return new WP_Error( 'unsupported_object_type', 'Unsupported object type' ); } /** * Returns a list of order_item objects by their IDs. * * @param array $ids List of order_item IDs to fetch. * @param string $order Either 'ASC' or 'DESC'. * * @access public * * @return array|object|null */ public function get_order_item_by_ids( $ids, $order = '' ) { global $wpdb; if ( ! is_array( $ids ) ) { return array(); } // Make sure the IDs are numeric and are non-zero. $ids = array_filter( array_map( 'intval', $ids ) ); if ( empty( $ids ) ) { return array(); } // Prepare the placeholders for the prepared query below. $placeholders = implode( ',', array_fill( 0, count( $ids ), '%d' ) ); $query = "SELECT * FROM {$this->order_item_table_name} WHERE order_item_id IN ( $placeholders )"; if ( ! empty( $order ) && in_array( $order, array( 'ASC', 'DESC' ), true ) ) { $query .= " ORDER BY order_item_id $order"; } // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared return $wpdb->get_results( $wpdb->prepare( $query, $ids ), ARRAY_A ); } /** * Build the full sync action object for WooCommerce order items. * * @access public * * @param array $args An array with the order items and the previous end. * * @return array An array with the order items, order item meta and the previous end. */ public function build_full_sync_action_array( $args ) { list( $filtered_order_items, $previous_end ) = $args; return array( 'order_items' => $filtered_order_items['objects'], 'order_item_meta' => $filtered_order_items['meta'], 'previous_end' => $previous_end, ); } /** * Given the Module Configuration and Status return the next chunk of items to send. * This function also expands the posts and metadata and filters them based on the maximum size constraints. * * @param array $config This module Full Sync configuration. * @param array $status This module Full Sync status. * @param int $chunk_size Chunk size. * * @return array */ public function get_next_chunk( $config, $status, $chunk_size ) { $order_item_ids = parent::get_next_chunk( $config, $status, $chunk_size ); if ( empty( $order_item_ids ) ) { return array(); } // Fetch the order items in DESC order for the next chunk logic to work. $order_items = $this->get_order_item_by_ids( $order_item_ids, 'DESC' ); // If no orders were fetched, make sure to return the expected structure so that status is updated correctly. if ( empty( $order_items ) ) { return array( 'object_ids' => $order_item_ids, 'objects' => array(), ); } // Get the order IDs from the orders that were fetched. $fetched_order_item_ids = wp_list_pluck( $order_items, 'order_item_id' ); $metadata = $this->get_metadata( $fetched_order_item_ids, 'order_item', static::$order_item_meta_whitelist ); // Filter the orders and metadata based on the maximum size constraints. list( $filtered_order_item_ids, $filtered_order_items, $filtered_order_items_metadata ) = $this->filter_objects_and_metadata_by_size( 'order_item', $order_items, $metadata, self::MAX_META_LENGTH, self::MAX_SIZE_FULL_SYNC ); return array( 'object_ids' => $filtered_order_item_ids, 'objects' => $filtered_order_items, 'meta' => $filtered_order_items_metadata, ); } }