Exemplo n.º 1
0
						<div class="field-wrap">
							<input type="text" name="sale_price" value="<?php 
                    echo esc_attr(ThemexWoo::$data['product']['sale_price']);
                    ?>
" />
						</div>
					</td>
				</tr>
				<?php 
                }
                ?>
				<?php 
                if (in_array(ThemexCore::getOption('product_type', 'all'), array('all', 'physical'))) {
                    ?>
				<?php 
                    if (themex_taxonomy('product_shipping_class') && ThemexWoo::isShipping()) {
                        ?>
				<tr class="trigger-type-physical">
					<th><?php 
                        _e('Shipping Class', 'makery');
                        ?>
</th>
					<td>
						<div class="element-select">
							<span></span>
							<?php 
                        echo ThemexInterface::renderOption(array('id' => 'shipping_class', 'type' => 'select_category', 'taxonomy' => 'product_shipping_class', 'value' => ThemexWoo::$data['product']['shipping_class'], 'wrap' => false));
                        ?>
						</div>
					</td>
				</tr>
Exemplo n.º 2
0
 /**
  * Updates product
  *
  * @access public
  * @param int $ID
  * @param array $data
  * @return void
  */
 public static function updateProduct($ID, $data)
 {
     global $wpdb;
     $redirect = false;
     if (empty($ID)) {
         $ID = self::addProduct();
         $redirect = true;
     }
     $args = array('ID' => $ID);
     //title
     $args['post_title'] = themex_value('title', $data);
     if (empty($args['post_title'])) {
         ThemexInterface::$messages[] = __('Product name field is required', 'makery');
     }
     //category
     if (themex_taxonomy('product_cat')) {
         $category = intval(themex_value('category', $data));
         if (empty($category)) {
             ThemexInterface::$messages[] = __('Item category field is required', 'makery');
         } else {
             $term = get_term($category, 'product_cat');
             if (empty($term)) {
                 ThemexInterface::$messages[] = __('This item category does not exist', 'makery');
             } else {
                 wp_set_object_terms($ID, $term->name, 'product_cat');
             }
         }
     }
     //tags
     if (!ThemexCore::checkOption('product_tags')) {
         $tags = sanitize_text_field(themex_value('tags', $data));
         $tags = array_map('trim', explode(',', $tags));
         if (!empty($tags)) {
             $tag = reset($tags);
             if (empty($tag)) {
                 wp_set_object_terms($ID, null, 'product_tag');
             } else {
                 wp_set_object_terms($ID, $tags, 'product_tag');
             }
         }
     }
     //type
     $virtual = 'no';
     $ending = 'yes';
     if (themex_value('type', $data) == 'virtual' || ThemexCore::getOption('product_type', 'all') == 'virtual') {
         $virtual = 'yes';
         $ending = 'no';
     }
     update_post_meta($ID, '_virtual', $virtual);
     update_post_meta($ID, '_downloadable', $virtual);
     update_post_meta($ID, '_manage_stock', $ending);
     update_post_meta($ID, '_stock_status', 'instock');
     update_post_meta($ID, '_visibility', 'visible');
     //price
     if (!ThemexCore::checkOption('product_price')) {
         if (isset($data['regular_price'])) {
             $regular_price = round(floatval(themex_value('regular_price', $data)), 2);
             update_post_meta($ID, '_price', $regular_price);
             update_post_meta($ID, '_regular_price', $regular_price);
         }
         if (isset($data['sale_price'])) {
             $sale_price = round(floatval(themex_value('sale_price', $data)), 2);
             if (empty($sale_price)) {
                 $sale_price = '';
             }
             update_post_meta($ID, '_sale_price', $sale_price);
             if (!empty($sale_price)) {
                 update_post_meta($ID, '_price', $sale_price);
             }
         }
     }
     //stock
     if ($virtual == 'no' && isset($data['stock'])) {
         $stock = intval(themex_value('stock', $data));
         update_post_meta($ID, '_stock', $stock);
     }
     //shipping
     if (themex_taxonomy('product_shipping_class')) {
         $class = intval(themex_value('shipping_class', $data));
         $term = get_term($class, 'product_shipping_class');
         if (empty($class)) {
             wp_set_object_terms($ID, '', 'product_shipping_class');
         } else {
             if (!is_wp_error($term)) {
                 wp_set_object_terms($ID, $term->name, 'product_shipping_class');
             }
         }
     }
     //file
     if ($virtual == 'yes' && isset($_FILES['file'])) {
         $files = get_post_meta($ID, '_downloadable_files', true);
         if (empty($files) || !is_array($files)) {
             $files = array();
         }
         $extensions = array_map('trim', explode(',', ThemexCore::getOption('product_extensions', 'zip')));
         $attachment = ThemexCore::addFile($_FILES['file'], $extensions);
         if (isset($attachment['ID']) && $attachment['ID'] != 0) {
             $file = array_shift($files);
             if (is_array($file) && isset($file['file'])) {
                 $current = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid='%s'", $file['file']));
                 if (!empty($current)) {
                     wp_delete_attachment($current);
                 }
             }
             $files = array_merge(array(md5($attachment['guid']) => array('name' => themex_filename($attachment['guid']), 'file' => $attachment['guid'])), $files);
             update_post_meta($ID, '_downloadable_files', $files);
         }
     }
     //attributes
     if (!ThemexCore::checkOption('product_attributes')) {
         $attributes = self::getAttributes();
         $options = get_post_meta($ID, '_product_attributes', true);
         if (empty($options) || !is_array($options)) {
             $options = array();
         }
         foreach ($attributes as $attribute) {
             if (isset($data[$attribute['name']]) && taxonomy_exists($attribute['name'])) {
                 $name = stripslashes(strip_tags($data[$attribute['name']]));
                 $value = sanitize_title($data[$attribute['name']]);
                 if ($attribute['type'] != 'select' || (isset($attribute['options'][$value]) || $value == '')) {
                     if ($attribute['type'] == 'select') {
                         wp_set_object_terms($ID, $value, $attribute['name']);
                     } else {
                         wp_set_object_terms($ID, $name, $attribute['name']);
                     }
                     if ($value != '') {
                         $options[$attribute['name']] = array('name' => $attribute['name'], 'value' => $value, 'position' => '0', 'is_visible' => 1, 'is_variation' => 0, 'is_taxonomy' => 1);
                     } else {
                         unset($options[$attribute['name']]);
                     }
                 }
             }
         }
         update_post_meta($ID, '_product_attributes', $options);
     }
     //options
     $option_names = themex_array('option_names', $data);
     $option_values = themex_array('option_values', $data);
     if (is_array($option_names) && is_array($option_values)) {
         $slugs = array();
         $options = get_post_meta($ID, '_product_attributes', true);
         if (empty($options) || !is_array($options)) {
             $options = array();
         }
         foreach ($option_names as $index => $name) {
             if (isset($option_values[$index])) {
                 $name = sanitize_text_field($name);
                 $slug = sanitize_title($name);
                 $value = implode('|', array_map('trim', explode(',', sanitize_text_field($option_values[$index]))));
                 if (!empty($slug) && !empty($name) && !empty($value)) {
                     $slugs[] = $slug;
                     $options[$slug] = array('name' => $name, 'value' => $value, 'position' => '0', 'is_visible' => 0, 'is_variation' => 1, 'is_taxonomy' => 0);
                 }
             }
         }
         foreach ($options as $slug => $option) {
             if (isset($option['is_taxonomy']) && empty($option['is_taxonomy']) && !in_array($slug, $slugs)) {
                 unset($options[$slug]);
             }
         }
         update_post_meta($ID, '_product_attributes', $options);
     }
     //variations
     $variation_ids = themex_array('variation_ids', $data);
     $variation_stocks = themex_array('variation_stocks', $data);
     $variation_regular_prices = themex_array('variation_regular_prices', $data);
     $variation_sale_prices = themex_array('variation_sale_prices', $data);
     if (is_array($variation_ids) && is_array($variation_stocks) && is_array($variation_regular_prices) && is_array($variation_sale_prices)) {
         $variations = self::getVariations($ID, array('fields' => 'ids'));
         $new_variations = array();
         foreach ($variation_ids as $index => $variation_id) {
             if (isset($variation_stocks[$index]) && isset($variation_regular_prices[$index]) && isset($variation_sale_prices[$index])) {
                 $variation_id = intval($variation_id);
                 $stock = intval($variation_stocks[$index]);
                 $regular_price = intval($variation_regular_prices[$index]);
                 $sale_price = $variation_sale_prices[$index];
                 if (!empty($stock) && (empty($variation_id) || !in_array($variation_id, $variations))) {
                     $variation_id = wp_insert_post(array('post_type' => 'product_variation', 'post_parent' => $ID, 'post_status' => 'publish', 'post_author' => 1, 'post_title' => sprintf(__('Variation #%s', 'makery'), count($variations) + 1)));
                 }
                 if (!empty($variation_id)) {
                     $new_variations[] = $variation_id;
                     if (($variation_index = array_search($variation_id, $variations)) !== false) {
                         unset($variations[$variation_index]);
                     }
                     update_post_meta($variation_id, '_manage_stock', 'yes');
                     update_post_meta($variation_id, '_stock_status', 'instock');
                     update_post_meta($variation_id, '_stock', $stock);
                     update_post_meta($variation_id, '_regular_price', $regular_price);
                     update_post_meta($variation_id, '_price', $regular_price);
                     if ($sale_price != '') {
                         update_post_meta($variation_id, '_sale_price', intval($sale_price));
                         update_post_meta($variation_id, '_price', intval($sale_price));
                     }
                     $options = self::getOptions($ID);
                     foreach ($options as $name => $option) {
                         $values = themex_array('variation_' . $name . 's', $data);
                         $items = array_map('trim', explode(',', $option['value']));
                         if (is_array($values) && isset($values[$index]) && (in_array($values[$index], $items) || $values[$index] == '')) {
                             update_post_meta($variation_id, 'attribute_' . $name, $values[$index]);
                         }
                     }
                 }
             }
         }
         set_transient('wc_product_children_ids_' . $ID . WC_Cache_Helper::get_transient_version('product'), $new_variations, 84600 * 365);
         foreach ($variations as $variation) {
             wp_delete_post($variation, true);
         }
         WC_Product_Variable::sync($ID);
         if (empty($new_variations)) {
             wp_set_object_terms($ID, 'simple', 'product_type');
         } else {
             wp_set_object_terms($ID, 'variable', 'product_type');
         }
     }
     //content
     $args['post_content'] = trim(themex_value('content', $data));
     $args['post_content'] = wp_kses($args['post_content'], array('strong' => array(), 'em' => array(), 'a' => array('href' => array(), 'title' => array(), 'target' => array()), 'p' => array(), 'br' => array()));
     if (empty(ThemexInterface::$messages)) {
         $status = get_post_status($ID);
         if ($status == 'draft') {
             $args['post_status'] = 'pending';
             if (ThemexCore::checkOption('shop_approve')) {
                 $args['post_status'] = 'publish';
             }
             $redirect = true;
         }
         ThemexInterface::$messages[] = __('Product has been successfully saved', 'makery');
         $_POST['success'] = true;
     }
     //update post
     wp_update_post($args);
     if ($redirect) {
         wp_redirect(ThemexCore::getURL('shop-product', $ID));
         exit;
     }
 }
				<tr>
					<th><?php 
_e('Keywords', 'makery');
?>
</th>
					<td>
						<div class="field-wrap">
							<input type="text" name="s" value="<?php 
the_search_query();
?>
" />
						</div>
					</td>
				</tr>
				<?php 
if (themex_taxonomy('shop_category')) {
    ?>
				<tr>
					<th><?php 
    _e('Category', 'makery');
    ?>
</th>
					<td>
						<div class="element-select">
							<span></span>
							<?php 
    echo ThemexInterface::renderOption(array('id' => 'category', 'type' => 'select_category', 'taxonomy' => 'shop_category', 'value' => esc_attr(themex_array('category', $_GET)), 'wrap' => false));
    ?>
						</div>
					</td>
				</tr>
Exemplo n.º 4
0
 /**
  * Updates shop profile
  *
  * @access public
  * @param int $ID
  * @param array $data
  * @return void
  */
 public static function updateProfile($ID, $data)
 {
     $redirect = false;
     if (empty($ID)) {
         $ID = self::addShop();
         $redirect = true;
     }
     $args = array('ID' => $ID);
     //title
     $title = trim(themex_value('title', $data));
     if (empty($title)) {
         ThemexInterface::$messages[] = __('Shop name field is required', 'makery');
     } else {
         $args['post_title'] = $title;
     }
     //category
     if (themex_taxonomy('shop_category')) {
         $category = intval(themex_value('category', $data));
         if (empty($category)) {
             ThemexInterface::$messages[] = __('Shop category field is required', 'makery');
         } else {
             $term = get_term($category, 'shop_category');
             if (empty($term)) {
                 ThemexInterface::$messages[] = __('This shop category does not exist', 'makery');
             } else {
                 wp_set_object_terms($ID, $term->name, 'shop_category');
             }
         }
     }
     //content
     $content = trim(themex_value('content', $data));
     if (empty($content)) {
         ThemexInterface::$messages[] = __('Shop description field is required', 'makery');
     } else {
         $args['post_content'] = wp_kses($content, array('strong' => array(), 'em' => array(), 'a' => array('href' => array(), 'title' => array(), 'target' => array()), 'p' => array(), 'br' => array()));
     }
     ThemexCore::updatePostMeta($ID, 'about', themex_value('about', $data));
     ThemexCore::updatePostMeta($ID, 'policy', themex_value('policy', $data));
     if (empty(ThemexInterface::$messages)) {
         $status = get_post_status($ID);
         if ($status == 'draft') {
             $args['post_status'] = 'pending';
             if (ThemexCore::checkOption('shop_approve')) {
                 $args['post_status'] = 'publish';
             }
             $redirect = true;
         } else {
             ThemexInterface::$messages[] = __('Shop has been successfully saved', 'makery');
             $_POST['success'] = true;
         }
     }
     //update post
     wp_update_post($args);
     if ($redirect && empty(ThemexInterface::$messages)) {
         wp_redirect(ThemexCore::getURL('shop-settings'));
         exit;
     }
 }