Automattic\WooCommerce\Internal

OrderCouponDataMigrator::convert_item()privateWC 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.

Метод класса: OrderCouponDataMigrator{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->convert_item( $meta_id, $meta_value );
$meta_id(int) (обязательный)
Value of 'meta_id' of the row being converted.
$meta_value(строка) (обязательный)
Value of 'meta_value' of the row being converted.

Код OrderCouponDataMigrator::convert_item() WC 9.7.1

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 );
	}
}