Automattic\WooCommerce\Internal\DataStores\Fulfillments

FulfillmentsDataStore::update_metapublicWC 1.0

Method to save the metadata for a fulfillment.

Method of the class: FulfillmentsDataStore{}

No Hooks.

Returns

Int. Number of rows updated.

Usage

$FulfillmentsDataStore = new FulfillmentsDataStore();
$FulfillmentsDataStore->update_meta( $data, $meta ): int;
$data(Fulfillment) (required) (passed by reference — &)
The fulfillment object to save.
$meta(WC_Meta_Data) (required)
Meta object (containing at least ->id).

FulfillmentsDataStore::update_meta() code WC 10.3.6

public function update_meta( &$data, $meta ): int {
	// Update the metadata for the fulfillment.
	global $wpdb;

	$data_id = $data->get_id();

	// Prevent updating metadata for a deleted fulfillment.
	if ( $data->get_date_deleted() ) {
		throw new \Exception( esc_html__( 'Cannot update meta for a deleted fulfillment.', 'woocommerce' ) );
	}

	$rows_updated = $wpdb->update(
		$wpdb->prefix . 'wc_order_fulfillment_meta',
		array(
			'meta_value' => wp_json_encode( $meta->value ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
		),
		array(
			'fulfillment_id' => $data_id,
			'meta_id'        => $meta->id,
			'meta_key'       => $meta->key, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
		),
		array(
			'%s',
		),
		array(
			'%d',
			'%d',
			'%s',
		)
	);

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

	return $rows_updated;
}