WC_Post_Data::wp_insert_post_data( array $data )

Forces the order posts to have a title in a certain format (containing the date).


Description Description

Forces certain product data based on the product’s type, e.g. grouped products cannot have a parent.


Parameters Parameters

$data

(Required) An array of slashed post data.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class-wc-post-data.php

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

		return $data;
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.