Automattic\WooCommerce\Internal\DataStores\Fulfillments

FulfillmentsDataStore::deletepublicWC 1.0

Method to delete a fulfillment from the database.

Method of the class: FulfillmentsDataStore{}

Returns

null. Nothing (null).

Usage

$FulfillmentsDataStore = new FulfillmentsDataStore();
$FulfillmentsDataStore->delete( $data, $args ): void;
$data(Fulfillment) (required) (passed by reference — &)
The fulfillment object to delete.
$args(array)
Optional arguments to pass to the delete method.
Default: array()

FulfillmentsDataStore::delete() code WC 10.3.6

public function delete( &$data, $args = array() ): void {
	// If the record is already deleted, do nothing.
	if ( $data->get_date_deleted() ) {
		return;
	}

	/**
	 * Filter to modify the fulfillment data before it is updated.
	 *
	 * @since 10.1.0
	 */
	$data = apply_filters( 'woocommerce_fulfillment_before_delete', $data );

	// Soft Delete the fulfillment from the database.
	global $wpdb;

	$data_id       = $data->get_id();
	$deletion_time = current_time( 'mysql' );
	$wpdb->update(
		$wpdb->prefix . 'wc_order_fulfillments',
		array( 'date_deleted' => $deletion_time ),
		array(
			'fulfillment_id' => $data_id,
			'date_deleted'   => null,
		),
		array( '%s' ),
		array( '%d' )
	);

	// Check for errors.
	if ( $wpdb->last_error ) {
		throw new \Exception( esc_html__( 'Failed to delete fulfillment.', 'woocommerce' ) );
	}

	$data->set_date_deleted( $deletion_time );
	$data->apply_changes();
	$data->set_object_read( true );

	if ( ! doing_action( 'woocommerce_fulfillment_after_delete' ) ) {
		/**
		 * Action to perform after a fulfillment is deleted.
		 *
		 * @since 10.1.0
		 */
		do_action( 'woocommerce_fulfillment_after_delete', $data );
	}

	// Set the fulfillment object to a fresh state.
	$data = new Fulfillment();
}