Automattic\WooCommerce\Internal\DataStores\Fulfillments
FulfillmentsDataStore::read_fulfillments
Method to read the fulfillment data.
Method of the class: FulfillmentsDataStore{}
No Hooks.
Returns
Fulfillment[]. Fulfillment object.
Usage
$FulfillmentsDataStore = new FulfillmentsDataStore(); $FulfillmentsDataStore->read_fulfillments( $entity_type, $entity_id, $with_deleted ): array;
- $entity_type(string) (required)
- The entity type.
- $entity_id(string) (required)
- The entity ID.
- $with_deleted(true|false)
- Whether to include deleted fulfillments in the results.
Default: false
FulfillmentsDataStore::read_fulfillments() FulfillmentsDataStore::read fulfillments code WC 10.3.6
public function read_fulfillments( string $entity_type, string $entity_id, bool $with_deleted = false ): array {
// Read the fulfillment data from the database.
global $wpdb;
if ( ! $with_deleted ) {
$fulfillment_data = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}wc_order_fulfillments WHERE entity_type = %s AND entity_id = %s AND date_deleted IS NULL",
$entity_type,
$entity_id
),
ARRAY_A
);
} else {
$fulfillment_data = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}wc_order_fulfillments WHERE entity_type = %s AND entity_id = %s",
$entity_type,
$entity_id
),
ARRAY_A
);
}
if ( is_wp_error( $fulfillment_data ) ) {
throw new \Exception( esc_html__( 'Failed to read fulfillment data.', 'woocommerce' ) );
}
// Create Fulfillment objects from the data.
$fulfillments = array();
foreach ( $fulfillment_data as $data ) {
// Note: Don't initialize with ID, it will cause a re-read from the database.
// Set the ID directly after the object is created.
$fulfillment = new Fulfillment();
$fulfillment->set_id( $data['fulfillment_id'] );
$fulfillment->set_props( $data );
$fulfillment->apply_changes();
$fulfillment->set_object_read( true );
// Read the metadata for the fulfillment.
$fulfillment->read_meta_data( true );
$fulfillments[] = $fulfillment;
}
return $fulfillments;
}