Merge branch 'template-creation-fix' into 'master'
Template creation fix See merge request saburly/wiaas/new-wiaas!42
This commit was merged in pull request #42.
This commit is contained in:
@@ -4,12 +4,13 @@ class Wiaas_Admin_Product {
|
|||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
|
||||||
add_action('acf/save_post', array(__CLASS__, 'wiaas_my_save_post'), 20, 1);
|
add_action('acf/save_post', array(__CLASS__, 'save_initial_product_country_and_type'), 20, 1);
|
||||||
add_action('woocommerce_after_register_post_type', array(__CLASS__, 'wiaas_register_product_status'));
|
add_action('woocommerce_after_register_post_type', array(__CLASS__, 'wiaas_register_product_status'));
|
||||||
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'wiaas_modify_product'));
|
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'wiaas_modify_product'));
|
||||||
add_action('add_meta_boxes', array(__CLASS__, 'wiaas_maybe_remove_metaboxes'), 999);
|
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_filter('wp_insert_post_data', array(__CLASS__, 'wiaas_maybe_set_no_country_status'), 999, 2);
|
||||||
add_action('acf/render_field/type=taxonomy', array(__CLASS__, 'wiaas_render_field'), 10, 1);
|
|
||||||
|
add_action('acf/render_field/type=group', array(__CLASS__, 'render_choose_button_for_new_product'), 10, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,13 +29,12 @@ class Wiaas_Admin_Product {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function render_choose_button_for_new_product($field) {
|
||||||
|
|
||||||
public static function wiaas_render_field($field) {
|
if ($field['_name'] === '_wiaas_product_general') {
|
||||||
|
|
||||||
if ($field['_name'] === '_wiaas_product_country') {
|
|
||||||
?>
|
?>
|
||||||
<div id="submitpost" style="padding: 20px;">
|
<div id="submitpost" style="padding: 20px 0;">
|
||||||
<input style="float:right;" name="save" id="save-post" class="button" type="submit" value="Choose"/>
|
<input style="float:right;" name="publish" id="publish" class="button button-large button-primary" type="submit" value="Choose"/>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
@@ -53,8 +53,7 @@ class Wiaas_Admin_Product {
|
|||||||
|
|
||||||
$post_id = $post->ID;
|
$post_id = $post->ID;
|
||||||
|
|
||||||
if ($post_id === 0 ||
|
if ($post_id === 0 || $post->post_status === '_wiaas_no_country') {
|
||||||
($post->post_status !== 'publish' && !(Wiaas_Countries::get_package_country(wc_get_product($post_id))))) {
|
|
||||||
|
|
||||||
remove_meta_box('woocommerce-product-data', 'product', 'normal');
|
remove_meta_box('woocommerce-product-data', 'product', 'normal');
|
||||||
remove_meta_box('submitdiv', 'product', 'side');
|
remove_meta_box('submitdiv', 'product', 'side');
|
||||||
@@ -99,24 +98,54 @@ class Wiaas_Admin_Product {
|
|||||||
* @param $post_id
|
* @param $post_id
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static function wiaas_my_save_post($post_id) {
|
public static function save_initial_product_country_and_type($post_id) {
|
||||||
|
|
||||||
global $post;
|
global $post;
|
||||||
$status = get_post_status( $post->ID);
|
|
||||||
|
|
||||||
$value = get_field('_wiaas_product_country', $post_id, true);
|
if ($post->post_type !== 'product') {
|
||||||
$type = get_field('_wiaas_product_type', $post_id, true);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($value) && $status === '_wiaas_no_country' ) {
|
$general = get_field('_wiaas_product_general', $post_id);
|
||||||
|
|
||||||
wp_set_object_terms($post_id, $value, 'product_country', true);
|
$country = $general['_wiaas_product_country'];
|
||||||
wp_set_object_terms($post_id, $type, 'product_type', true);
|
$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(
|
wp_update_post(array(
|
||||||
'ID' => $post_id,
|
'ID' => $post_id,
|
||||||
'post_status' => 'draft'
|
'post_status' => 'draft'
|
||||||
));
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
"title": "General",
|
"title": "General",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"key": "field_5bc0965a35406",
|
"key": "field_5bceef4c9771c",
|
||||||
"label": "Type",
|
"label": "General",
|
||||||
"name": "_wiaas_product_type",
|
"name": "_wiaas_product_general",
|
||||||
"type": "select",
|
"type": "group",
|
||||||
"instructions": "",
|
"instructions": "",
|
||||||
"required": 0,
|
"required": 0,
|
||||||
"conditional_logic": 0,
|
"conditional_logic": 0,
|
||||||
@@ -16,48 +16,65 @@
|
|||||||
"class": "",
|
"class": "",
|
||||||
"id": ""
|
"id": ""
|
||||||
},
|
},
|
||||||
"choices": {
|
"layout": "block",
|
||||||
"simple": "Simple",
|
"sub_fields": [
|
||||||
"bundle": "Bundle",
|
{
|
||||||
"wiaastemplate": "Template"
|
"key": "field_5bc0965a35406",
|
||||||
},
|
"label": "Type",
|
||||||
"default_value": [],
|
"name": "_wiaas_product_type",
|
||||||
"allow_null": 0,
|
"type": "select",
|
||||||
"multiple": 0,
|
"instructions": "",
|
||||||
"ui": 1,
|
"required": 0,
|
||||||
"ajax": 0,
|
"conditional_logic": 0,
|
||||||
"return_format": "value",
|
"wrapper": {
|
||||||
"placeholder": ""
|
"width": "",
|
||||||
},
|
"class": "",
|
||||||
{
|
"id": ""
|
||||||
"key": "field_5bbf899bba1af",
|
},
|
||||||
"label": "Country",
|
"choices": {
|
||||||
"name": "_wiaas_product_country",
|
"simple": "Simple",
|
||||||
"type": "taxonomy",
|
"bundle": "Bundle",
|
||||||
"instructions": "",
|
"wiaastemplate": "Template"
|
||||||
"required": 0,
|
},
|
||||||
"conditional_logic": [
|
"default_value": [],
|
||||||
[
|
"allow_null": 0,
|
||||||
{
|
"multiple": 0,
|
||||||
"field": "field_5bc0965a35406",
|
"ui": 1,
|
||||||
"operator": "!=",
|
"ajax": 0,
|
||||||
"value": "wiaastemplate"
|
"return_format": "value",
|
||||||
}
|
"placeholder": ""
|
||||||
]
|
},
|
||||||
],
|
{
|
||||||
"wrapper": {
|
"key": "field_5bbf899bba1af",
|
||||||
"width": "",
|
"label": "Country",
|
||||||
"class": "",
|
"name": "_wiaas_product_country",
|
||||||
"id": ""
|
"type": "taxonomy",
|
||||||
},
|
"instructions": "",
|
||||||
"taxonomy": "product_country",
|
"required": 1,
|
||||||
"field_type": "select",
|
"conditional_logic": [
|
||||||
"allow_null": 0,
|
[
|
||||||
"add_term": 0,
|
{
|
||||||
"save_terms": 1,
|
"field": "field_5bc0965a35406",
|
||||||
"load_terms": 1,
|
"operator": "!=",
|
||||||
"return_format": "id",
|
"value": "wiaastemplate"
|
||||||
"multiple": 0
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"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": [
|
"location": [
|
||||||
@@ -76,7 +93,7 @@
|
|||||||
],
|
],
|
||||||
"menu_order": 0,
|
"menu_order": 0,
|
||||||
"position": "acf_after_title",
|
"position": "acf_after_title",
|
||||||
"style": "default",
|
"style": "seamless",
|
||||||
"label_placement": "top",
|
"label_placement": "top",
|
||||||
"instruction_placement": "label",
|
"instruction_placement": "label",
|
||||||
"hide_on_screen": "",
|
"hide_on_screen": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user