Fix template creation
This commit is contained in:
@@ -4,12 +4,11 @@ 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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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() {
|
public static function wiaas_maybe_remove_metaboxes() {
|
||||||
$screen = get_current_screen();
|
$screen = get_current_screen();
|
||||||
$screen_id = $screen ? $screen->id : '';
|
$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))))) {
|
($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');
|
||||||
remove_meta_box('slugdiv', 'product', 'normal');
|
remove_meta_box('slugdiv', 'product', 'normal');
|
||||||
remove_meta_box('wiaas_upload_and_link_document', 'product', 'normal');
|
remove_meta_box('wiaas_upload_and_link_document', 'product', 'normal');
|
||||||
remove_meta_box('postexcerpt', '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('tagsdiv-supplier', 'product', 'side');
|
||||||
remove_meta_box('postimagediv', 'product', 'side');
|
remove_meta_box('postimagediv', 'product', 'side');
|
||||||
remove_meta_box('woocommerce-product-images', '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('wiaas_upload_and_link_document', 'product', 'side');
|
||||||
remove_meta_box('radio-tagsdiv-product_country', 'product', 'side');
|
remove_meta_box('radio-tagsdiv-product_country', 'product', 'side');
|
||||||
remove_meta_box('tagsdiv-_wiaas_shop_prices', 'product', 'side');
|
remove_meta_box('tagsdiv-_wiaas_shop_prices', 'product', 'side');
|
||||||
@@ -99,24 +85,28 @@ 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') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$country = get_field('_wiaas_product_country', $post_id, true);
|
||||||
$type = get_field('_wiaas_product_type', $post_id, true);
|
$type = get_field('_wiaas_product_type', $post_id, true);
|
||||||
|
|
||||||
if (!empty($value) && $status === '_wiaas_no_country' ) {
|
if (empty($type) || ( empty($country) && $type !== 'wiaastemplate' )) {
|
||||||
|
|
||||||
wp_set_object_terms($post_id, $value, 'product_country', true);
|
|
||||||
wp_set_object_terms($post_id, $type, 'product_type', true);
|
|
||||||
|
|
||||||
wp_update_post(array(
|
wp_update_post(array(
|
||||||
'ID' => $post_id,
|
'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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
"name": "_wiaas_product_country",
|
"name": "_wiaas_product_country",
|
||||||
"type": "taxonomy",
|
"type": "taxonomy",
|
||||||
"instructions": "",
|
"instructions": "",
|
||||||
"required": 0,
|
"required": 1,
|
||||||
"conditional_logic": [
|
"conditional_logic": [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user