WC_Meta_Box_Product_Images::save │ public static │ WC 1.0

Save meta box data.

Method of the class: WC_Meta_Box_Product_Images{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WC_Meta_Box_Product_Images::save( $post_id, $post );
$post_id(int) (required)
.
$post(WP_Post) (required)
.

WC_Meta_Box_Product_Images::save() code WC 11.1.2

public static function save( $post_id, $post ) {
	$product_type = empty( $_POST['product-type'] ) ? WC_Product_Factory::get_product_type( $post_id ) : sanitize_title( wp_unslash( $_POST['product-type'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
	$classname    = WC_Product_Factory::get_product_classname( $post_id, $product_type ? $product_type : ProductType::SIMPLE );
	$product      = new $classname( $post_id );

	if ( ! $product instanceof WC_Product ) {
		return;
	}

	$attachment_ids = isset( $_POST['product_image_gallery'] ) ? array_filter( explode( ',', wc_clean( $_POST['product_image_gallery'] ) ) ) : array();
	$videos_enabled = ProductMediaGallery::is_feature_enabled();

	if ( ! $videos_enabled ) {
		$product->set_gallery_image_ids( $attachment_ids );
		$product->save();
		return;
	}

	$media_gallery = array();

	if ( isset( $_POST['product_media_gallery'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
		$posted_media_gallery = wc_clean( wp_unslash( $_POST['product_media_gallery'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
		$media_gallery        = ProductMediaGallery::normalize_media_gallery_items(
			self::decode_media_gallery_json( $posted_media_gallery )
		);
		$attachment_ids       = ProductMediaGallery::get_image_ids( $media_gallery );
	}

	$product->set_gallery_image_ids( $attachment_ids );
	$product->save();

	ProductMediaGallery::set_stored_video_gallery_items(
		$product,
		ProductMediaGallery::get_positioned_video_gallery_items_from_media_gallery( $media_gallery )
	);
}