Fix template creation

This commit is contained in:
Almira Krdzic
2018-10-23 11:28:11 +02:00
parent 00999122a2
commit e3869e720b
2 changed files with 17 additions and 27 deletions

View File

@@ -4,12 +4,11 @@ class Wiaas_Admin_Product {
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_filter('woocommerce_register_post_type_product', array(__CLASS__, 'wiaas_modify_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=taxonomy', array(__CLASS__, 'wiaas_render_field'), 10, 1);
}
@@ -29,19 +28,6 @@ class Wiaas_Admin_Product {
}
public static function wiaas_render_field($field) {
if ($field['_name'] === '_wiaas_product_country') {
?>
<div id="submitpost" style="padding: 20px;">
<input style="float:right;" name="save" id="save-post" class="button" type="submit" value="Choose"/>
</div>
<?php
}
}
public static function wiaas_maybe_remove_metaboxes() {
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
@@ -57,7 +43,7 @@ class Wiaas_Admin_Product {
($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('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');
@@ -73,7 +59,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');
@@ -99,24 +85,28 @@ class Wiaas_Admin_Product {
* @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;
$status = get_post_status( $post->ID);
$value = get_field('_wiaas_product_country', $post_id, true);
if ($post->post_type !== 'product') {
return;
}
$country = get_field('_wiaas_product_country', $post_id, true);
$type = get_field('_wiaas_product_type', $post_id, true);
if (!empty($value) && $status === '_wiaas_no_country' ) {
wp_set_object_terms($post_id, $value, 'product_country', true);
wp_set_object_terms($post_id, $type, 'product_type', true);
if (empty($type) || ( empty($country) && $type !== 'wiaastemplate' )) {
wp_update_post(array(
'ID' => $post_id,
'post_status' => 'draft'
'post_status' => '_wiaas_no_country'
));
}
wp_set_object_terms($post_id, $type, 'product_type', true);
if ($type !== 'wiaastemplate') {
wp_set_object_terms($post_id, $country, 'product_country', true);
}
}

View File

@@ -35,7 +35,7 @@
"name": "_wiaas_product_country",
"type": "taxonomy",
"instructions": "",
"required": 0,
"required": 1,
"conditional_logic": [
[
{