/**
* Update course data from eg structure
* @param int $parent_post_id
* @param array $course
* @return null
*/
private function insertPaymentTypeVariation( $parent_post_id, $course ) {
// Payment type for eg currently has only 1 option: Pay Upfront
$variation_post_title = $course->Title. ' - Pay Upfront';
$variation_post = [
'post_title' => $variation_post_title,
'post_type' => 'product_variation', // product
'post_status' => 'publish',
'post_parent' => $parent_post_id,
'menu_order' => $menu_order
];
global $wpdb;
// $isChildPostExist = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'product_variation' AND post_parent = '$parent_post_id' AND post_title = '$variation_post_title' " );
$search_args = array(
'post_type' => 'product_variation',
'post_status' => 'publish',
'post_parent' => $parent_post_id,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => $this->attribute_payment_type,
'value' => 'Pay Upfront',
),
array(
'key' => $this->attribute_start_date,
'value' => '', // Default option do not have start-date value
)
)
);
$results = new WP_Query( $search_args );
// if( empty( $isChildPostExist ) ) {
if( count( $results->posts ) < 1 ) {
$variation_post_id = wp_insert_post($variation_post);
// Update each child post variation option metadata
update_post_meta( $variation_post_id, '_virtual', 'yes' );
update_post_meta( $variation_post_id, $this->attribute_payment_type, "Pay Upfront");
update_post_meta( $variation_post_id, $this->attribute_start_date, '');
}
}
Comments
Post a Comment