Code Duplication    Length = 24-24 lines in 2 locations

includes/abstracts/abstract-wc-order.php 1 location

@@ 408-431 (lines=24) @@
405
	/**
406
	 * Update Meta Data in the database.
407
	 */
408
	protected function save_meta_data() {
409
		global $wpdb;
410
		$all_meta_ids = array_map( 'absint', $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d", $this->get_id() ) . " AND meta_key NOT IN ('" . implode( "','", array_map( 'esc_sql', $this->get_internal_meta_keys() ) ) . "');" ) );
411
		$set_meta_ids = array();
412
413
		foreach ( $this->_meta_data as $meta_id => $meta ) {
414
			if ( 'new' === substr( $meta_id, 0, 3 ) ) {
415
				$set_meta_ids[] = add_metadata( 'post', $this->get_id(), $meta->key, $meta->value, false );
416
			} else {
417
				update_metadata_by_mid( 'post', $meta_id, $meta->value, $meta->key );
418
				$set_meta_ids[] = absint( $meta_id );
419
			}
420
		}
421
422
		// Delete no longer set meta data
423
		$delete_meta_ids = array_diff( $all_meta_ids, $set_meta_ids );
424
425
		foreach ( $delete_meta_ids as $meta_id ) {
426
			delete_metadata_by_mid( 'post', $meta_id );
427
		}
428
429
		WC_Cache_Helper::incr_cache_prefix( 'order_meta' );
430
		$this->read_meta_data();
431
	}
432
433
	/*
434
	|--------------------------------------------------------------------------

includes/class-wc-order-item.php 1 location

@@ 459-482 (lines=24) @@
456
	/**
457
	 * Update Meta Data in the database.
458
	 */
459
	protected function save_meta_data() {
460
		global $wpdb;
461
		$all_meta_ids = array_map( 'absint', $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = %d", $this->get_id() ) . " AND meta_key NOT IN ('" . implode( "','", array_map( 'esc_sql', $this->get_internal_meta_keys() ) ) . "');" ) );
462
		$set_meta_ids = array();
463
464
		foreach ( $this->_meta_data as $meta_id => $meta ) {
465
			if ( 'new' === substr( $meta_id, 0, 3 ) ) {
466
				$set_meta_ids[] = add_metadata( 'order_item', $this->get_id(), $meta->key, $meta->value, false );
467
			} else {
468
				update_metadata_by_mid( 'order_item', $meta_id, $meta->value, $meta->key );
469
				$set_meta_ids[] = absint( $meta_id );
470
			}
471
		}
472
473
		// Delete no longer set meta data
474
		$delete_meta_ids = array_diff( $all_meta_ids, $set_meta_ids );
475
476
		foreach ( $delete_meta_ids as $meta_id ) {
477
			delete_metadata_by_mid( 'order_item', $meta_id );
478
		}
479
480
		WC_Cache_Helper::incr_cache_prefix( 'order_itemmeta' );
481
		$this->read_meta_data();
482
	}
483
484
	/*
485
	|--------------------------------------------------------------------------