WC_Post_Data::wp_insert_post_data()public staticWC 1.0

Forces the order posts to have a title in a certain format (containing the date). Forces certain product data based on the product's type, e.g. grouped products cannot have a parent.

Method of the class: WC_Post_Data{}

No Hooks.

Return

Array.

Usage

$result = WC_Post_Data::wp_insert_post_data( $data );
$data(array) (required)
An array of slashed post data.

WC_Post_Data::wp_insert_post_data() code WC 8.6.1

public static function wp_insert_post_data( $data ) {
	if ( 'shop_order' === $data['post_type'] && isset( $data['post_date'] ) ) {
		$order_title = 'Order';
		if ( $data['post_date'] ) {
			$order_title .= ' – ' . date_i18n( 'F j, Y @ h:i A', strtotime( $data['post_date'] ) );
		}
		$data['post_title'] = $order_title;
	} elseif ( 'product' === $data['post_type'] && isset( $_POST['product-type'] ) ) { // WPCS: input var ok, CSRF ok.
		$product_type = wc_clean( wp_unslash( $_POST['product-type'] ) ); // WPCS: input var ok, CSRF ok.
		switch ( $product_type ) {
			case 'grouped':
			case 'variable':
				$data['post_parent'] = 0;
				break;
		}
	} elseif ( 'product' === $data['post_type'] && 'auto-draft' === $data['post_status'] ) {
		$data['post_title'] = 'AUTO-DRAFT';
	} elseif ( 'shop_coupon' === $data['post_type'] ) {
		// Coupons should never allow unfiltered HTML.
		$data['post_title'] = wp_filter_kses( $data['post_title'] );
	}

	return $data;
}