validate country
This commit is contained in:
@@ -10,6 +10,8 @@ class Wiaas_Admin_Product {
|
||||
add_action('add_meta_boxes', array(__CLASS__, 'wiaas_maybe_remove_metaboxes'), 999);
|
||||
add_filter('wp_insert_post_data', array(__CLASS__, 'wiaas_maybe_set_no_country_status'), 999, 2);
|
||||
|
||||
add_action('acf/render_field/type=group', array(__CLASS__, 'render_choose_button_for_new_product'), 10, 1);
|
||||
|
||||
}
|
||||
|
||||
public static function wiaas_modify_product($args) {
|
||||
@@ -27,6 +29,18 @@ class Wiaas_Admin_Product {
|
||||
));
|
||||
}
|
||||
|
||||
public static function render_choose_button_for_new_product($field) {
|
||||
|
||||
if ($field['_name'] === '_wiaas_product_general') {
|
||||
?>
|
||||
<div id="submitpost" style="padding: 20px 0;">
|
||||
<input style="float:right;" name="publish" id="publish" class="button button-large button-primary" type="submit" value="Choose"/>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function wiaas_maybe_remove_metaboxes() {
|
||||
$screen = get_current_screen();
|
||||
@@ -39,11 +53,10 @@ class Wiaas_Admin_Product {
|
||||
|
||||
$post_id = $post->ID;
|
||||
|
||||
if ($post_id === 0 ||
|
||||
($post->post_status !== 'publish' && !(Wiaas_Countries::get_package_country(wc_get_product($post_id))))) {
|
||||
if ($post_id === 0 || $post->post_status === '_wiaas_no_country') {
|
||||
|
||||
remove_meta_box('woocommerce-product-data', 'product', 'normal');
|
||||
// remove_meta_box('submitdiv', 'product', 'side');
|
||||
remove_meta_box('submitdiv', 'product', 'side');
|
||||
remove_meta_box('slugdiv', 'product', 'normal');
|
||||
remove_meta_box('wiaas_upload_and_link_document', 'product', 'normal');
|
||||
remove_meta_box('postexcerpt', 'product', 'normal');
|
||||
@@ -59,7 +72,7 @@ class Wiaas_Admin_Product {
|
||||
remove_meta_box('tagsdiv-supplier', 'product', 'side');
|
||||
remove_meta_box('postimagediv', 'product', 'side');
|
||||
remove_meta_box('woocommerce-product-images', 'product', 'side');
|
||||
// remove_meta_box('submitdiv', 'product', 'side');
|
||||
remove_meta_box('submitdiv', 'product', 'side');
|
||||
remove_meta_box('wiaas_upload_and_link_document', 'product', 'side');
|
||||
remove_meta_box('radio-tagsdiv-product_country', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-_wiaas_shop_prices', 'product', 'side');
|
||||
@@ -93,21 +106,47 @@ class Wiaas_Admin_Product {
|
||||
return;
|
||||
}
|
||||
|
||||
$country = get_field('_wiaas_product_country', $post_id, true);
|
||||
$type = get_field('_wiaas_product_type', $post_id, true);
|
||||
$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'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
"title": "General",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bc0965a35406",
|
||||
"label": "Type",
|
||||
"name": "_wiaas_product_type",
|
||||
"type": "select",
|
||||
"key": "field_5bceef4c9771c",
|
||||
"label": "General",
|
||||
"name": "_wiaas_product_general",
|
||||
"type": "group",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
@@ -16,48 +16,65 @@
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"choices": {
|
||||
"simple": "Simple",
|
||||
"bundle": "Bundle",
|
||||
"wiaastemplate": "Template"
|
||||
},
|
||||
"default_value": [],
|
||||
"allow_null": 0,
|
||||
"multiple": 0,
|
||||
"ui": 1,
|
||||
"ajax": 0,
|
||||
"return_format": "value",
|
||||
"placeholder": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bbf899bba1af",
|
||||
"label": "Country",
|
||||
"name": "_wiaas_product_country",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": [
|
||||
[
|
||||
{
|
||||
"field": "field_5bc0965a35406",
|
||||
"operator": "!=",
|
||||
"value": "wiaastemplate"
|
||||
}
|
||||
]
|
||||
],
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "product_country",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 0,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
"layout": "block",
|
||||
"sub_fields": [
|
||||
{
|
||||
"key": "field_5bc0965a35406",
|
||||
"label": "Type",
|
||||
"name": "_wiaas_product_type",
|
||||
"type": "select",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"choices": {
|
||||
"simple": "Simple",
|
||||
"bundle": "Bundle",
|
||||
"wiaastemplate": "Template"
|
||||
},
|
||||
"default_value": [],
|
||||
"allow_null": 0,
|
||||
"multiple": 0,
|
||||
"ui": 1,
|
||||
"ajax": 0,
|
||||
"return_format": "value",
|
||||
"placeholder": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bbf899bba1af",
|
||||
"label": "Country",
|
||||
"name": "_wiaas_product_country",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": [
|
||||
[
|
||||
{
|
||||
"field": "field_5bc0965a35406",
|
||||
"operator": "!=",
|
||||
"value": "wiaastemplate"
|
||||
}
|
||||
]
|
||||
],
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "product_country",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 0,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
@@ -76,7 +93,7 @@
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "acf_after_title",
|
||||
"style": "default",
|
||||
"style": "seamless",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
|
||||
Reference in New Issue
Block a user