Merge branch 'master' into bundle-cost-summary
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Product {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('acf/save_post', array(__CLASS__, 'wiaas_my_save_post'), 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);
|
||||
|
||||
}
|
||||
|
||||
public static function wiaas_modify_product($args) {
|
||||
$args['supports'] = array('title');
|
||||
return $args;
|
||||
}
|
||||
|
||||
public static function wiaas_register_product_status() {
|
||||
register_post_status('_wiaas_no_country', array(
|
||||
'label' => _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 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 : '';
|
||||
|
||||
if ($screen_id !== 'product') {
|
||||
return;
|
||||
}
|
||||
global $post;
|
||||
|
||||
$post_id = $post->ID;
|
||||
|
||||
if ($post_id === 0 ||
|
||||
($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('slugdiv', 'product', 'normal');
|
||||
remove_meta_box('wiaas_upload_and_link_document', 'product', 'normal');
|
||||
remove_meta_box('postexcerpt', 'product', 'normal');
|
||||
remove_meta_box('template_product_meta_box', 'product', 'normal');
|
||||
remove_meta_box('postimagediv', 'product', 'normal');
|
||||
remove_meta_box('woocommerce-product-images', 'product', 'normal');
|
||||
remove_meta_box('wc-jetpack-product_by_user_role', 'product', 'normal');
|
||||
|
||||
|
||||
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('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');
|
||||
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('radio-product_catdiv', '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 wiaas_my_save_post($post_id) {
|
||||
|
||||
global $post;
|
||||
$status = get_post_status( $post->ID);
|
||||
|
||||
$value = get_field('_wiaas_product_country', $post_id, true);
|
||||
$type = get_field('_wiaas_product_type', $post_id, true);
|
||||
|
||||
error_log($status);
|
||||
error_log($value);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'draft'
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Admin_Product::init();
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Simple_Product {
|
||||
|
||||
public static function init() {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/simple-product/class-wiaas-admin-product-additional-info.php';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Simple_Product::init();
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Product_Additional_Info {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('woocommerce_product_options_general_product_data', array(__CLASS__, 'display_additional_fields'));
|
||||
add_action('woocommerce_process_product_meta', array(__CLASS__, 'save_additional_fields'));
|
||||
add_filter('woocommerce_json_search_found_products', array(__CLASS__, 'filter_product_by_country'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add Manufacturer product and Supplier product number fields to
|
||||
* Simple product general tab
|
||||
*
|
||||
*/
|
||||
public static function display_additional_fields() {
|
||||
|
||||
global $post;
|
||||
$product = wc_get_product( $post->ID );
|
||||
|
||||
if ($product->get_type() === 'simple') {
|
||||
|
||||
echo '<div class=" product_custom_field ">';
|
||||
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_manufacturer_product_no',
|
||||
'label' => __('Manufacturer product number', 'woocommerce'),
|
||||
'type' => 'text'
|
||||
)
|
||||
);
|
||||
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_supplier_product_no',
|
||||
'label' => __('Supplier product number', 'woocommerce'),
|
||||
'type' => 'text'
|
||||
)
|
||||
);
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
public static function filter_product_by_country($search_results) {
|
||||
|
||||
$url = wp_get_referer();
|
||||
|
||||
if (strpos($url, 'post') === false) {
|
||||
return $search_results;
|
||||
}
|
||||
|
||||
$post_param = explode("&", parse_url($url, PHP_URL_QUERY))[0];
|
||||
$post_id = explode("=", $post_param)[1];
|
||||
$country_id = wp_get_post_terms($post_id, 'product_country', array('fields' => 'ids'))[0];
|
||||
|
||||
if (!empty($search_results)) {
|
||||
$search_result_objects = array_map('wc_get_product', array_keys($search_results));
|
||||
|
||||
foreach ($search_result_objects as $result_id => $producta) {
|
||||
if (Wiaas_Countries::get_product_country_term_id($producta) !== $country_id) {
|
||||
unset($search_results[$producta->get_id()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $search_results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Manufacturer product and Supplier product number fields to
|
||||
* Simple product meta data
|
||||
*
|
||||
*/
|
||||
public static function save_additional_fields($post_id) {
|
||||
|
||||
$manufacturer_product_no = $_POST['_manufacturer_product_no'];
|
||||
if (!empty($manufacturer_product_no))
|
||||
update_post_meta($post_id, '_manufacturer_product_no', esc_attr($manufacturer_product_no));
|
||||
|
||||
$supplier_product_no = $_POST['_supplier_product_no'];
|
||||
if (!empty($supplier_product_no))
|
||||
update_post_meta($post_id, '_supplier_product_no', esc_attr($supplier_product_no));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Product_Additional_Info::init();
|
||||
Reference in New Issue
Block a user