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.
Return Return
(array)
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;
}