_x('No Country', 'Product status', 'wiaas'),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => false,
'show_in_admin_status_list' => false,
));
}
public static function render_choose_button_for_new_product($field) {
if ($field['_name'] === '_wiaas_product_general') {
?>
id : '';
if ($screen_id !== 'product') {
return;
}
global $post;
$post_id = $post->ID;
if ($post_id === 0 || $post->post_status === '_wiaas_no_country') {
remove_meta_box('woocommerce-product-data', 'product', 'normal');
remove_meta_box('slugdiv', 'product', 'normal');
remove_meta_box('postexcerpt', 'product', 'normal');
remove_meta_box('template_product_meta_box', 'product', 'normal');
remove_meta_box('submitdiv', 'product', 'side');
remove_meta_box('groups-permissions', 'product', 'side');
remove_meta_box('tagsdiv-product_tag', 'product', 'side');
remove_meta_box('tagsdiv-template_category', 'product', 'side');
remove_meta_box('tagsdiv-supplier', 'product', 'side');
remove_meta_box('postimagediv', 'product', 'side');
remove_meta_box('woocommerce-product-images', 'product', 'side');
remove_meta_box('wiaas_upload_and_link_document', 'product', 'side');
remove_meta_box('tagsdiv-product_country', 'product', 'side');
remove_meta_box('tagsdiv-wiaas_units', 'product', 'side');
}
//Always hide product category, it is added wit advanced custom fields plugin for simple product
remove_meta_box('product_catdiv', 'product', 'side');
// Always hide
remove_meta_box('tagsdiv-product_country', 'product', 'side');
}
public static function wiaas_maybe_set_no_country_status($data, $postarr) {
if ($postarr['post_type'] === 'product' && (!isset($postarr['ID']) || !$postarr['ID'])) {
$data['post_status'] = '_wiaas_no_country';
}
return $data;
}
/**
* Check for post status and and if there is country available
* Set post status to draft if the country is added
*
* @param $post_id
*/
public static function save_initial_product_country_and_type($post_id) {
global $post;
if ($post->post_type !== 'product') {
return;
}
$general = get_field('_wiaas_product_general', $post_id);
$country = $general['_wiaas_product_country'];
$type = $general['_wiaas_product_type'];
/**
* If type is missing set status to no country
*
* If this is not template product type and country is missing set status to no country
*
*/
if (empty($type) || ( empty($country) && $type !== 'wiaastemplate' )) {
wp_update_post(array(
'ID' => $post_id,
'post_status' => '_wiaas_no_country'
));
return;
}
/**
* Country and type are selected for simple and bundle products so
* link them
*/
wp_set_object_terms($post_id, $type, 'product_type', true);
if ($type !== 'wiaastemplate') {
wp_set_object_terms($post_id, $country, 'product_country', true);
}
/**
* If product had no country status change it to draft status
*/
if ($post->post_status === '_wiaas_no_country') {
wp_update_post(array(
'ID' => $post_id,
'post_status' => 'draft'
));
}
}
}
Wiaas_Admin_Product::init();