Automattic\WooCommerce\Internal

OrderCouponDataMigrator::convert_itemprivateWC 1.0

Convert one verbose 'coupon_data' entry into a simplified 'coupon_info' entry.

The existing database row is updated in place, both the 'meta_key' and the 'meta_value' columns.

Method of the class: OrderCouponDataMigrator{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->convert_item( $meta_id, $meta_value );
$meta_id(int) (required)
Value of 'meta_id' of the row being converted.
$meta_value(string) (required)
Value of 'meta_value' of the row being converted.

OrderCouponDataMigrator::convert_item() code WC 10.7.0

private function convert_item( int $meta_id, string $meta_value ) {
	global $wpdb;

	//phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
	$coupon_data = unserialize( $meta_value );

	$temp_coupon = new \WC_Coupon();
	$temp_coupon->set_props( $coupon_data );

	//phpcs:disable WordPress.DB.SlowDBQuery
	$wpdb->update(
		"{$wpdb->prefix}woocommerce_order_itemmeta",
		array(
			'meta_key'   => 'coupon_info',
			'meta_value' => $temp_coupon->get_short_info(),
		),
		array( 'meta_id' => $meta_id )
	);
	//phpcs:enable WordPress.DB.SlowDBQuery

	if ( $wpdb->last_error ) {
		throw new Exception( $wpdb->last_error );
	}
}