/**
 * Products wrapper for get_posts.
 *
 * This function should be used for product retrieval so that we have a data agnostic
 * way to get a list of products.
 *
 * Args:
 *      status array|string List of statuses to find. Default: any. Options: any, draft, pending, private and publish.
 *      type array|string Product type, e.g. Default: all. Options: all, simple, external, variable, variation, grouped.
 *      parent int post/product parent
 *      sku string Limit result set to products with specific SKU.
 *      category array Limit result set to products assigned to specific categories by slug
 *                     e.g. array('hoodie', 'cap', 't-shirt').
 *      tag array Limit result set to products assigned to specific tags (by slug)
 *                e.g. array('funky', 'retro', 'designer')
 *      shipping_class array Limit results set to products in specific shipping classes (by slug)
 *                           e.g. array('standard', 'next-day')
 *      limit int Maximum of products to retrieve.
 *      offset int Offset of products to retrieve.
 *      page int Page of products to retrieve. Ignored when using the 'offset' arg.
 *      exclude array Product IDs to exclude from the query.
 *      orderby string Order by date, title, id, modified, rand etc
 *      order string ASC or DESC
 *      return string Type of data to return. Allowed values:
 *          ids array of Product ids
 *          objects array of product objects (default)
 *      paginate bool If true, the return value will be an array with values:
 *          'products'      => array of data (return value above),
 *          'total'         => total number of products matching the query
 *          'max_num_pages' => max number of pages found
 *
 * @since  2.7.0
 * @param  array $args Array of args (above)
 * @return array|stdClass Number of pages and an array of product objects if
 *                             paginate is true, or just an array of values.
 */
function wc_get_products($args)
{
    $args = wp_parse_args($args, array('status' => array('draft', 'pending', 'private', 'publish'), 'type' => array_merge(array_keys(wc_get_product_types())), 'parent' => null, 'sku' => '', 'category' => array(), 'tag' => array(), 'limit' => get_option('posts_per_page'), 'offset' => null, 'page' => 1, 'exclude' => array(), 'orderby' => 'date', 'order' => 'DESC', 'return' => 'objects', 'paginate' => false, 'shipping_class' => array()));
    // Handle some BW compatibility arg names where wp_query args differ in naming.
    $map_legacy = array('numberposts' => 'limit', 'post_status' => 'status', 'post_parent' => 'parent', 'posts_per_page' => 'limit', 'paged' => 'page');
    foreach ($map_legacy as $from => $to) {
        if (isset($args[$from])) {
            $args[$to] = $args[$from];
        }
    }
    return WC_Data_Store::load('product')->get_products($args);
}
 /**
  * Edit a product
  *
  * @since 2.2
  * @param int $id the product ID
  * @param array $data
  * @return array
  */
 public function edit_product($id, $data)
 {
     try {
         if (!isset($data['product'])) {
             throw new WC_API_Exception('woocommerce_api_missing_product_data', sprintf(__('No %1$s data specified to edit %1$s', 'woocommerce'), 'product'), 400);
         }
         $data = $data['product'];
         $id = $this->validate_request($id, 'product', 'edit');
         if (is_wp_error($id)) {
             return $id;
         }
         $data = apply_filters('woocommerce_api_edit_product_data', $data, $this);
         // Product title.
         if (isset($data['title'])) {
             wp_update_post(array('ID' => $id, 'post_title' => wc_clean($data['title'])));
         }
         // Product name (slug).
         if (isset($data['name'])) {
             wp_update_post(array('ID' => $id, 'post_name' => sanitize_title($data['name'])));
         }
         // Product status.
         if (isset($data['status'])) {
             wp_update_post(array('ID' => $id, 'post_status' => wc_clean($data['status'])));
         }
         // Product short description.
         if (isset($data['short_description'])) {
             // Enable short description html tags.
             $post_excerpt = isset($data['enable_html_short_description']) && true === $data['enable_html_short_description'] ? $data['short_description'] : wc_clean($data['short_description']);
             wp_update_post(array('ID' => $id, 'post_excerpt' => $post_excerpt));
         }
         // Product description.
         if (isset($data['description'])) {
             // Enable description html tags.
             $post_content = isset($data['enable_html_description']) && true === $data['enable_html_description'] ? $data['description'] : wc_clean($data['description']);
             wp_update_post(array('ID' => $id, 'post_content' => $post_content));
         }
         // Validate the product type
         if (isset($data['type']) && !in_array(wc_clean($data['type']), array_keys(wc_get_product_types()))) {
             throw new WC_API_Exception('woocommerce_api_invalid_product_type', sprintf(__('Invalid product type - the product type must be any of these: %s', 'woocommerce'), implode(', ', array_keys(wc_get_product_types()))), 400);
         }
         // Check for featured/gallery images, upload it and set it
         if (isset($data['images'])) {
             $this->save_product_images($id, $data['images']);
         }
         // Save product meta fields
         $this->save_product_meta($id, $data);
         // Save variations
         $product = get_product($id);
         if ($product->is_type('variable')) {
             if (isset($data['variations']) && is_array($data['variations'])) {
                 $this->save_variations($id, $data);
             } else {
                 // Just sync variations
                 WC_Product_Variable::sync($id);
             }
         }
         do_action('woocommerce_api_edit_product', $id, $data);
         // Clear cache/transients
         wc_delete_product_transients($id);
         return $this->get_product($id);
     } catch (WC_API_Exception $e) {
         return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
     }
 }
 /**
  * Function to save coupon code to database
  *
  * @param int $post_id
  * @param object $post
  */
 public function woocommerce_process_product_meta_coupons($post_id, $post)
 {
     if (empty($post_id) || empty($post) || empty($_POST)) {
         return;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     if (is_int(wp_is_post_revision($post))) {
         return;
     }
     if (is_int(wp_is_post_autosave($post))) {
         return;
     }
     if (empty($_POST['woocommerce_meta_nonce']) || !wp_verify_nonce($_POST['woocommerce_meta_nonce'], 'woocommerce_save_data')) {
         return;
     }
     if (!current_user_can('edit_post', $post_id)) {
         return;
     }
     if ($post->post_type != 'product') {
         return;
     }
     $valid_product_types = function_exists('wc_get_product_types') ? array_keys(wc_get_product_types()) : array('simple', 'variable', 'subscription', 'variable-subscription');
     if (!empty($_POST['product-type']) && in_array($_POST['product-type'], $valid_product_types)) {
         if (!empty($_POST['_coupon_title'])) {
             if ($this->is_wc_gte_23()) {
                 $coupon_titles = array_filter(array_map('trim', explode(',', $_POST['_coupon_title'])));
             } else {
                 $coupon_titles = $_POST['_coupon_title'];
             }
             update_post_meta($post_id, '_coupon_title', $coupon_titles);
         } else {
             update_post_meta($post_id, '_coupon_title', array());
         }
     }
     if ($_POST['product-type'] == 'subscription' || $_POST['product-type'] == 'variable-subscription') {
         if (isset($_POST['send_coupons_on_renewals'])) {
             update_post_meta($post_id, 'send_coupons_on_renewals', $_POST['send_coupons_on_renewals']);
         } else {
             update_post_meta($post_id, 'send_coupons_on_renewals', 'no');
         }
     }
 }
    /**
     * Output the metabox.
     *
     * @param WP_Post $post
     */
    public static function output($post)
    {
        global $post, $thepostid;
        wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce');
        $thepostid = $post->ID;
        if ($terms = wp_get_object_terms($post->ID, 'product_type')) {
            $product_type = sanitize_title(current($terms)->name);
        } else {
            $product_type = apply_filters('default_product_type', 'simple');
        }
        $type_box = '<label for="product-type"><select id="product-type" name="product-type"><optgroup label="' . esc_attr__('Product Type', 'woocommerce') . '">';
        foreach (wc_get_product_types() as $value => $label) {
            $type_box .= '<option value="' . esc_attr($value) . '" ' . selected($product_type, $value, false) . '>' . esc_html($label) . '</option>';
        }
        $type_box .= '</optgroup></select></label>';
        $product_type_options = apply_filters('product_type_options', array('virtual' => array('id' => '_virtual', 'wrapper_class' => 'show_if_simple', 'label' => __('Virtual', 'woocommerce'), 'description' => __('Virtual products are intangible and aren\'t shipped.', 'woocommerce'), 'default' => 'no'), 'downloadable' => array('id' => '_downloadable', 'wrapper_class' => 'show_if_simple', 'label' => __('Downloadable', 'woocommerce'), 'description' => __('Downloadable products give access to a file upon purchase.', 'woocommerce'), 'default' => 'no')));
        foreach ($product_type_options as $key => $option) {
            $selected_value = get_post_meta($post->ID, '_' . $key, true);
            if ('' == $selected_value && isset($option['default'])) {
                $selected_value = $option['default'];
            }
            $type_box .= '<label for="' . esc_attr($option['id']) . '" class="' . esc_attr($option['wrapper_class']) . ' tips" data-tip="' . esc_attr($option['description']) . '">' . esc_html($option['label']) . ': <input type="checkbox" name="' . esc_attr($option['id']) . '" id="' . esc_attr($option['id']) . '" ' . checked($selected_value, 'yes', false) . ' /></label>';
        }
        ?>
		<div class="panel-wrap product_data">

			<span class="type_box hidden"> &mdash; <?php 
        echo $type_box;
        ?>
</span>

			<ul class="product_data_tabs wc-tabs">
				<?php 
        $product_data_tabs = apply_filters('woocommerce_product_data_tabs', array('general' => array('label' => __('General', 'woocommerce'), 'target' => 'general_product_data', 'class' => array('hide_if_grouped')), 'inventory' => array('label' => __('Inventory', 'woocommerce'), 'target' => 'inventory_product_data', 'class' => array('show_if_simple', 'show_if_variable', 'show_if_grouped', 'show_if_external')), 'shipping' => array('label' => __('Shipping', 'woocommerce'), 'target' => 'shipping_product_data', 'class' => array('hide_if_virtual', 'hide_if_grouped', 'hide_if_external')), 'linked_product' => array('label' => __('Linked Products', 'woocommerce'), 'target' => 'linked_product_data', 'class' => array()), 'attribute' => array('label' => __('Attributes', 'woocommerce'), 'target' => 'product_attributes', 'class' => array()), 'variations' => array('label' => __('Variations', 'woocommerce'), 'target' => 'variable_product_options', 'class' => array('variations_tab', 'show_if_variable')), 'advanced' => array('label' => __('Advanced', 'woocommerce'), 'target' => 'advanced_product_data', 'class' => array())));
        foreach ($product_data_tabs as $key => $tab) {
            ?>
<li class="<?php 
            echo $key;
            ?>
_options <?php 
            echo $key;
            ?>
_tab <?php 
            echo implode(' ', (array) $tab['class']);
            ?>
">
							<a href="#<?php 
            echo $tab['target'];
            ?>
"><?php 
            echo esc_html($tab['label']);
            ?>
</a>
						</li><?php 
        }
        do_action('woocommerce_product_write_panel_tabs');
        ?>
			</ul>
			<div id="general_product_data" class="panel woocommerce_options_panel"><?php 
        echo '<div class="options_group show_if_external">';
        // External URL
        woocommerce_wp_text_input(array('id' => '_product_url', 'label' => __('Product URL', 'woocommerce'), 'placeholder' => 'http://', 'description' => __('Enter the external URL to the product.', 'woocommerce')));
        // Button text
        woocommerce_wp_text_input(array('id' => '_button_text', 'label' => __('Button text', 'woocommerce'), 'placeholder' => _x('Buy product', 'placeholder', 'woocommerce'), 'description' => __('This text will be shown on the button linking to the external product.', 'woocommerce')));
        echo '</div>';
        echo '<div class="options_group pricing show_if_simple show_if_external hidden">';
        // Price
        woocommerce_wp_text_input(array('id' => '_regular_price', 'label' => __('Regular price', 'woocommerce') . ' (' . get_woocommerce_currency_symbol() . ')', 'data_type' => 'price'));
        // Special Price
        woocommerce_wp_text_input(array('id' => '_sale_price', 'data_type' => 'price', 'label' => __('Sale price', 'woocommerce') . ' (' . get_woocommerce_currency_symbol() . ')', 'description' => '<a href="#" class="sale_schedule">' . __('Schedule', 'woocommerce') . '</a>'));
        // Special Price date range
        $sale_price_dates_from = ($date = get_post_meta($thepostid, '_sale_price_dates_from', true)) ? date_i18n('Y-m-d', $date) : '';
        $sale_price_dates_to = ($date = get_post_meta($thepostid, '_sale_price_dates_to', true)) ? date_i18n('Y-m-d', $date) : '';
        echo '<p class="form-field sale_price_dates_fields">
								<label for="_sale_price_dates_from">' . __('Sale price dates', 'woocommerce') . '</label>
								<input type="text" class="short" name="_sale_price_dates_from" id="_sale_price_dates_from" value="' . esc_attr($sale_price_dates_from) . '" placeholder="' . _x('From&hellip;', 'placeholder', 'woocommerce') . ' YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />
								<input type="text" class="short" name="_sale_price_dates_to" id="_sale_price_dates_to" value="' . esc_attr($sale_price_dates_to) . '" placeholder="' . _x('To&hellip;', 'placeholder', 'woocommerce') . '  YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />
								<a href="#" class="cancel_sale_schedule">' . __('Cancel', 'woocommerce') . '</a>' . wc_help_tip(__('The sale will end at the beginning of the set date.', 'woocommerce')) . '
							</p>';
        do_action('woocommerce_product_options_pricing');
        echo '</div>';
        echo '<div class="options_group show_if_downloadable hidden">';
        ?>
					<div class="form-field downloadable_files">
						<label><?php 
        _e('Downloadable files', 'woocommerce');
        ?>
</label>
						<table class="widefat">
							<thead>
								<tr>
									<th class="sort">&nbsp;</th>
									<th><?php 
        _e('Name', 'woocommerce');
        ?>
 <?php 
        echo wc_help_tip(__('This is the name of the download shown to the customer.', 'woocommerce'));
        ?>
</th>
									<th colspan="2"><?php 
        _e('File URL', 'woocommerce');
        ?>
 <?php 
        echo wc_help_tip(__('This is the URL or absolute path to the file which customers will get access to. URLs entered here should already be encoded.', 'woocommerce'));
        ?>
</th>
									<th>&nbsp;</th>
								</tr>
							</thead>
							<tbody>
								<?php 
        $downloadable_files = get_post_meta($post->ID, '_downloadable_files', true);
        if ($downloadable_files) {
            foreach ($downloadable_files as $key => $file) {
                include 'views/html-product-download.php';
            }
        }
        ?>
							</tbody>
							<tfoot>
								<tr>
									<th colspan="5">
										<a href="#" class="button insert" data-row="<?php 
        $file = array('file' => '', 'name' => '');
        ob_start();
        include 'views/html-product-download.php';
        echo esc_attr(ob_get_clean());
        ?>
"><?php 
        _e('Add File', 'woocommerce');
        ?>
</a>
									</th>
								</tr>
							</tfoot>
						</table>
					</div>
					<?php 
        // Download Limit
        woocommerce_wp_text_input(array('id' => '_download_limit', 'label' => __('Download limit', 'woocommerce'), 'placeholder' => __('Unlimited', 'woocommerce'), 'description' => __('Leave blank for unlimited re-downloads.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0')));
        // Expirey
        woocommerce_wp_text_input(array('id' => '_download_expiry', 'label' => __('Download expiry', 'woocommerce'), 'placeholder' => __('Never', 'woocommerce'), 'description' => __('Enter the number of days before a download link expires, or leave blank.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0')));
        // Download Type
        woocommerce_wp_select(array('id' => '_download_type', 'label' => __('Download type', 'woocommerce'), 'description' => sprintf(__('Choose a download type - this controls the <a href="%s">schema</a>.', 'woocommerce'), 'http://schema.org/'), 'options' => array('' => __('Standard Product', 'woocommerce'), 'application' => __('Application/Software', 'woocommerce'), 'music' => __('Music', 'woocommerce'))));
        do_action('woocommerce_product_options_downloads');
        echo '</div>';
        if (wc_tax_enabled()) {
            echo '<div class="options_group show_if_simple show_if_external show_if_variable">';
            // Tax
            woocommerce_wp_select(array('id' => '_tax_status', 'label' => __('Tax status', 'woocommerce'), 'options' => array('taxable' => __('Taxable', 'woocommerce'), 'shipping' => __('Shipping only', 'woocommerce'), 'none' => _x('None', 'Tax status', 'woocommerce')), 'desc_tip' => 'true', 'description' => __('Define whether or not the entire product is taxable, or just the cost of shipping it.', 'woocommerce')));
            $tax_classes = WC_Tax::get_tax_classes();
            $classes_options = array();
            $classes_options[''] = __('Standard', 'woocommerce');
            if (!empty($tax_classes)) {
                foreach ($tax_classes as $class) {
                    $classes_options[sanitize_title($class)] = esc_html($class);
                }
            }
            woocommerce_wp_select(array('id' => '_tax_class', 'label' => __('Tax class', 'woocommerce'), 'options' => $classes_options, 'desc_tip' => 'true', 'description' => __('Choose a tax class for this product. Tax classes are used to apply different tax rates specific to certain types of product.', 'woocommerce')));
            do_action('woocommerce_product_options_tax');
            echo '</div>';
        }
        do_action('woocommerce_product_options_general_product_data');
        ?>
			</div>

			<div id="inventory_product_data" class="panel woocommerce_options_panel hidden">

				<?php 
        echo '<div class="options_group">';
        // SKU
        if (wc_product_sku_enabled()) {
            woocommerce_wp_text_input(array('id' => '_sku', 'label' => '<abbr title="' . __('Stock Keeping Unit', 'woocommerce') . '">' . __('SKU', 'woocommerce') . '</abbr>', 'desc_tip' => 'true', 'description' => __('SKU refers to a Stock-keeping unit, a unique identifier for each distinct product and service that can be purchased.', 'woocommerce')));
        } else {
            echo '<input type="hidden" name="_sku" value="' . esc_attr(get_post_meta($thepostid, '_sku', true)) . '" />';
        }
        do_action('woocommerce_product_options_sku');
        if ('yes' === get_option('woocommerce_manage_stock')) {
            // manage stock
            woocommerce_wp_checkbox(array('id' => '_manage_stock', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __('Manage stock?', 'woocommerce'), 'description' => __('Enable stock management at product level', 'woocommerce')));
            do_action('woocommerce_product_options_stock');
            echo '<div class="stock_fields show_if_simple show_if_variable">';
            // Stock
            woocommerce_wp_text_input(array('id' => '_stock', 'label' => __('Stock quantity', 'woocommerce'), 'desc_tip' => true, 'description' => __('Stock quantity. If this is a variable product this value will be used to control stock for all variations, unless you define stock at variation level.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => 'any'), 'data_type' => 'stock'));
            // Backorders?
            woocommerce_wp_select(array('id' => '_backorders', 'label' => __('Allow backorders?', 'woocommerce'), 'options' => array('no' => __('Do not allow', 'woocommerce'), 'notify' => __('Allow, but notify customer', 'woocommerce'), 'yes' => __('Allow', 'woocommerce')), 'desc_tip' => true, 'description' => __('If managing stock, this controls whether or not backorders are allowed. If enabled, stock quantity can go below 0.', 'woocommerce')));
            do_action('woocommerce_product_options_stock_fields');
            echo '</div>';
        }
        // Stock status
        woocommerce_wp_select(array('id' => '_stock_status', 'wrapper_class' => 'hide_if_variable hide_if_external', 'label' => __('Stock status', 'woocommerce'), 'options' => array('instock' => __('In stock', 'woocommerce'), 'outofstock' => __('Out of stock', 'woocommerce')), 'desc_tip' => true, 'description' => __('Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce')));
        do_action('woocommerce_product_options_stock_status');
        echo '</div>';
        echo '<div class="options_group show_if_simple show_if_variable">';
        // Individual product
        woocommerce_wp_checkbox(array('id' => '_sold_individually', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __('Sold individually', 'woocommerce'), 'description' => __('Enable this to only allow one of this item to be bought in a single order', 'woocommerce')));
        do_action('woocommerce_product_options_sold_individually');
        echo '</div>';
        do_action('woocommerce_product_options_inventory_product_data');
        ?>

			</div>

			<div id="shipping_product_data" class="panel woocommerce_options_panel hidden">

				<?php 
        echo '<div class="options_group">';
        // Weight
        if (wc_product_weight_enabled()) {
            woocommerce_wp_text_input(array('id' => '_weight', 'label' => __('Weight', 'woocommerce') . ' (' . get_option('woocommerce_weight_unit') . ')', 'placeholder' => wc_format_localized_decimal(0), 'desc_tip' => 'true', 'description' => __('Weight in decimal form', 'woocommerce'), 'type' => 'text', 'data_type' => 'decimal'));
        }
        // Size fields
        if (wc_product_dimensions_enabled()) {
            ?>
<p class="form-field dimensions_field">
							<label for="product_length"><?php 
            echo __('Dimensions', 'woocommerce') . ' (' . get_option('woocommerce_dimension_unit') . ')';
            ?>
</label>
							<span class="wrap">
								<input id="product_length" placeholder="<?php 
            esc_attr_e('Length', 'woocommerce');
            ?>
" class="input-text wc_input_decimal" size="6" type="text" name="_length" value="<?php 
            echo esc_attr(wc_format_localized_decimal(get_post_meta($thepostid, '_length', true)));
            ?>
" />
								<input placeholder="<?php 
            esc_attr_e('Width', 'woocommerce');
            ?>
" class="input-text wc_input_decimal" size="6" type="text" name="_width" value="<?php 
            echo esc_attr(wc_format_localized_decimal(get_post_meta($thepostid, '_width', true)));
            ?>
" />
								<input placeholder="<?php 
            esc_attr_e('Height', 'woocommerce');
            ?>
" class="input-text wc_input_decimal last" size="6" type="text" name="_height" value="<?php 
            echo esc_attr(wc_format_localized_decimal(get_post_meta($thepostid, '_height', true)));
            ?>
" />
							</span>
							<?php 
            echo wc_help_tip(__('LxWxH in decimal form', 'woocommerce'));
            ?>
						</p><?php 
        }
        do_action('woocommerce_product_options_dimensions');
        echo '</div>';
        echo '<div class="options_group">';
        // Shipping Class
        $classes = get_the_terms($thepostid, 'product_shipping_class');
        if ($classes && !is_wp_error($classes)) {
            $current_shipping_class = current($classes)->term_id;
        } else {
            $current_shipping_class = '';
        }
        $args = array('taxonomy' => 'product_shipping_class', 'hide_empty' => 0, 'show_option_none' => __('No shipping class', 'woocommerce'), 'name' => 'product_shipping_class', 'id' => 'product_shipping_class', 'selected' => $current_shipping_class, 'class' => 'select short');
        ?>
<p class="form-field dimensions_field"><label for="product_shipping_class"><?php 
        _e('Shipping class', 'woocommerce');
        ?>
</label> <?php 
        wp_dropdown_categories($args);
        ?>
 <?php 
        echo wc_help_tip(__('Shipping classes are used by certain shipping methods to group similar products.', 'woocommerce'));
        ?>
</p><?php 
        do_action('woocommerce_product_options_shipping');
        echo '</div>';
        ?>

			</div>

			<div id="product_attributes" class="panel wc-metaboxes-wrapper hidden">
				<div class="toolbar toolbar-top">
					<span class="expand-close">
						<a href="#" class="expand_all"><?php 
        _e('Expand', 'woocommerce');
        ?>
</a> / <a href="#" class="close_all"><?php 
        _e('Close', 'woocommerce');
        ?>
</a>
					</span>
					<select name="attribute_taxonomy" class="attribute_taxonomy">
						<option value=""><?php 
        _e('Custom product attribute', 'woocommerce');
        ?>
</option>
						<?php 
        global $wc_product_attributes;
        // Array of defined attribute taxonomies
        $attribute_taxonomies = wc_get_attribute_taxonomies();
        if (!empty($attribute_taxonomies)) {
            foreach ($attribute_taxonomies as $tax) {
                $attribute_taxonomy_name = wc_attribute_taxonomy_name($tax->attribute_name);
                $label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name;
                echo '<option value="' . esc_attr($attribute_taxonomy_name) . '">' . esc_html($label) . '</option>';
            }
        }
        ?>
					</select>
					<button type="button" class="button add_attribute"><?php 
        _e('Add', 'woocommerce');
        ?>
</button>
				</div>
				<div class="product_attributes wc-metaboxes">
					<?php 
        // Product attributes - taxonomies and custom, ordered, with visibility and variation attributes set
        $attributes = maybe_unserialize(get_post_meta($thepostid, '_product_attributes', true));
        // Output All Set Attributes
        if (!empty($attributes)) {
            $attribute_keys = array_keys($attributes);
            $attribute_total = sizeof($attribute_keys);
            for ($i = 0; $i < $attribute_total; $i++) {
                $attribute = $attributes[$attribute_keys[$i]];
                $position = empty($attribute['position']) ? 0 : absint($attribute['position']);
                $taxonomy = '';
                $metabox_class = array();
                if ($attribute['is_taxonomy']) {
                    $taxonomy = $attribute['name'];
                    if (!taxonomy_exists($taxonomy)) {
                        continue;
                    }
                    $attribute_taxonomy = $wc_product_attributes[$taxonomy];
                    $metabox_class[] = 'taxonomy';
                    $metabox_class[] = $taxonomy;
                    $attribute_label = wc_attribute_label($taxonomy);
                } else {
                    $attribute_label = apply_filters('woocommerce_attribute_label', $attribute['name'], $attribute['name'], false);
                }
                include 'views/html-product-attribute.php';
            }
        }
        ?>
				</div>
				<div class="toolbar">
					<span class="expand-close">
						<a href="#" class="expand_all"><?php 
        _e('Expand', 'woocommerce');
        ?>
</a> / <a href="#" class="close_all"><?php 
        _e('Close', 'woocommerce');
        ?>
</a>
					</span>
					<button type="button" class="button save_attributes button-primary"><?php 
        _e('Save attributes', 'woocommerce');
        ?>
</button>
				</div>
				<?php 
        do_action('woocommerce_product_options_attributes');
        ?>
			</div>
			<div id="linked_product_data" class="panel woocommerce_options_panel hidden">

				<div class="options_group">

					<p class="form-field">
						<label for="upsell_ids"><?php 
        _e('Up-sells', 'woocommerce');
        ?>
</label>
						<input type="hidden" class="wc-product-search" style="width: 50%;" id="upsell_ids" name="upsell_ids" data-placeholder="<?php 
        esc_attr_e('Search for a product&hellip;', 'woocommerce');
        ?>
" data-action="woocommerce_json_search_products" data-multiple="true" data-exclude="<?php 
        echo intval($post->ID);
        ?>
" data-selected="<?php 
        $product_ids = array_filter(array_map('absint', (array) get_post_meta($post->ID, '_upsell_ids', true)));
        $json_ids = array();
        foreach ($product_ids as $product_id) {
            $product = wc_get_product($product_id);
            if (is_object($product)) {
                $json_ids[$product_id] = wp_kses_post(html_entity_decode($product->get_formatted_name(), ENT_QUOTES, get_bloginfo('charset')));
            }
        }
        echo esc_attr(json_encode($json_ids));
        ?>
" value="<?php 
        echo implode(',', array_keys($json_ids));
        ?>
" /> <?php 
        echo wc_help_tip(__('Up-sells are products which you recommend instead of the currently viewed product, for example, products that are more profitable or better quality or more expensive.', 'woocommerce'));
        ?>
					</p>

					<p class="form-field">
						<label for="crosssell_ids"><?php 
        _e('Cross-sells', 'woocommerce');
        ?>
</label>
						<input type="hidden" class="wc-product-search" style="width: 50%;" id="crosssell_ids" name="crosssell_ids" data-placeholder="<?php 
        esc_attr_e('Search for a product&hellip;', 'woocommerce');
        ?>
" data-action="woocommerce_json_search_products" data-multiple="true" data-exclude="<?php 
        echo intval($post->ID);
        ?>
" data-selected="<?php 
        $product_ids = array_filter(array_map('absint', (array) get_post_meta($post->ID, '_crosssell_ids', true)));
        $json_ids = array();
        foreach ($product_ids as $product_id) {
            $product = wc_get_product($product_id);
            if (is_object($product)) {
                $json_ids[$product_id] = wp_kses_post(html_entity_decode($product->get_formatted_name(), ENT_QUOTES, get_bloginfo('charset')));
            }
        }
        echo esc_attr(json_encode($json_ids));
        ?>
" value="<?php 
        echo implode(',', array_keys($json_ids));
        ?>
" /> <?php 
        echo wc_help_tip(__('Cross-sells are products which you promote in the cart, based on the current product.', 'woocommerce'));
        ?>
					</p>
				</div>

				<div class="options_group grouping show_if_simple show_if_external">

					<p class="form-field">
						<label for="parent_id"><?php 
        _e('Grouping', 'woocommerce');
        ?>
</label>
						<input type="hidden" class="wc-product-search" style="width: 50%;" id="parent_id" name="parent_id" data-placeholder="<?php 
        esc_attr_e('Search for a product&hellip;', 'woocommerce');
        ?>
" data-action="woocommerce_json_search_grouped_products" data-allow_clear="true" data-multiple="false" data-exclude="<?php 
        echo intval($post->ID);
        ?>
" data-selected="<?php 
        $parent_id = absint($post->post_parent);
        if ($parent_id) {
            $parent = wc_get_product($parent_id);
            if (is_object($parent)) {
                $parent_title = wp_kses_post(html_entity_decode($parent->get_formatted_name(), ENT_QUOTES, get_bloginfo('charset')));
            }
            echo esc_attr($parent_title);
        }
        ?>
" value="<?php 
        echo $parent_id ? $parent_id : '';
        ?>
" /> <?php 
        echo wc_help_tip(__('Set this option to make this product part of a grouped product.', 'woocommerce'));
        ?>
					</p>

					<?php 
        woocommerce_wp_hidden_input(array('id' => 'previous_parent_id', 'value' => absint($post->post_parent)));
        do_action('woocommerce_product_options_grouping');
        ?>
				</div>

				<?php 
        do_action('woocommerce_product_options_related');
        ?>
			</div>

			<div id="advanced_product_data" class="panel woocommerce_options_panel hidden">

				<div class="options_group hide_if_external">
					<?php 
        // Purchase note
        woocommerce_wp_textarea_input(array('id' => '_purchase_note', 'label' => __('Purchase note', 'woocommerce'), 'desc_tip' => 'true', 'description' => __('Enter an optional note to send the customer after purchase.', 'woocommerce')));
        ?>
				</div>

				<div class="options_group">
					<?php 
        // menu_order
        woocommerce_wp_text_input(array('id' => 'menu_order', 'label' => __('Menu order', 'woocommerce'), 'desc_tip' => 'true', 'description' => __('Custom ordering position.', 'woocommerce'), 'value' => intval($post->menu_order), 'type' => 'number', 'custom_attributes' => array('step' => '1')));
        ?>
				</div>

				<div class="options_group reviews">
					<?php 
        woocommerce_wp_checkbox(array('id' => 'comment_status', 'label' => __('Enable reviews', 'woocommerce'), 'cbvalue' => 'open', 'value' => esc_attr($post->comment_status)));
        do_action('woocommerce_product_options_reviews');
        ?>
				</div>

				<?php 
        do_action('woocommerce_product_options_advanced');
        ?>

			</div>

			<?php 
        self::output_variations();
        do_action('woocommerce_product_data_panels');
        do_action('woocommerce_product_write_panels');
        // _deprecated
        ?>

			<div class="clear"></div>

		</div>
		<?php 
    }
 /**
  * Update one or more products.
  *
  * ## OPTIONS
  *
  * <id>
  * : Product ID
  *
  * --<field>=<value>
  * : One or more fields to update.
  *
  * ## AVAILABLE_FIELDS
  *
  * For more fields, see: wp wc product create --help
  *
  * ## EXAMPLES
  *
  *     wp wc product update 123 --title="New Product Title" --description="New description"
  *
  * @since 2.5.0
  */
 public function update($args, $assoc_args)
 {
     try {
         $id = $args[0];
         $data = apply_filters('woocommerce_cli_update_product_data', $this->unflatten_array($assoc_args));
         // Product title.
         if (isset($data['title'])) {
             wp_update_post(array('ID' => $id, 'post_title' => wc_clean($data['title'])));
         }
         // Product name (slug).
         if (isset($data['name'])) {
             wp_update_post(array('ID' => $id, 'post_name' => sanitize_title($data['name'])));
         }
         // Product status.
         if (isset($data['status'])) {
             wp_update_post(array('ID' => $id, 'post_status' => wc_clean($data['status'])));
         }
         // Product short description.
         if (isset($data['short_description'])) {
             // Enable short description html tags.
             $post_excerpt = isset($data['enable_html_short_description']) && true === $data['enable_html_short_description'] ? $data['short_description'] : wc_clean($data['short_description']);
             wp_update_post(array('ID' => $id, 'post_excerpt' => $post_excerpt));
         }
         // Product description.
         if (isset($data['description'])) {
             // Enable description html tags.
             $post_content = isset($data['enable_html_description']) && true === $data['enable_html_description'] ? $data['description'] : wc_clean($data['description']);
             wp_update_post(array('ID' => $id, 'post_content' => $post_content));
         }
         // Validate the product type
         if (isset($data['type']) && !in_array(wc_clean($data['type']), array_keys(wc_get_product_types()))) {
             throw new WC_CLI_Exception('woocommerce_cli_invalid_product_type', sprintf(__('Invalid product type - the product type must be any of these: %s', 'woocommerce'), implode(', ', array_keys(wc_get_product_types()))));
         }
         // Check for featured/gallery images, upload it and set it
         if (isset($data['images'])) {
             $this->save_product_images($id, $data['images']);
         }
         // Save product meta fields
         $this->save_product_meta($id, $data);
         // Save variations
         if (isset($data['type']) && 'variable' == $data['type'] && isset($data['variations']) && is_array($data['variations'])) {
             $this->save_variations($id, $data);
         }
         do_action('woocommerce_cli_update_product', $id, $data);
         // Clear cache/transients
         wc_delete_product_transients($id);
         WP_CLI::success("Updated product {$id}.");
     } catch (WC_CLI_Exception $e) {
         WP_CLI::error($e->getMessage());
     }
 }
 /**
  * Get the query params for collections of attachments.
  *
  * @return array
  */
 public function get_collection_params()
 {
     $params = parent::get_collection_params();
     $params['slug'] = array('description' => __('Limit result set to products with a specific slug.', 'woocommerce'), 'type' => 'string', 'validate_callback' => 'rest_validate_request_arg');
     $params['status'] = array('default' => 'any', 'description' => __('Limit result set to products assigned a specific status.', 'woocommerce'), 'type' => 'string', 'enum' => array_merge(array('any'), array_keys(get_post_statuses())), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg');
     $params['type'] = array('description' => __('Limit result set to products assigned a specific type.', 'woocommerce'), 'type' => 'string', 'enum' => array_keys(wc_get_product_types()), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg');
     $params['sku'] = array('description' => __('Limit result set to products with a specific SKU.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     $params['featured'] = array('description' => __('Limit result set to featured products.', 'woocommerce'), 'type' => 'boolean', 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg');
     $params['category'] = array('description' => __('Limit result set to products assigned a specific category ID.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg');
     $params['tag'] = array('description' => __('Limit result set to products assigned a specific tag ID.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg');
     $params['shipping_class'] = array('description' => __('Limit result set to products assigned a specific shipping class ID.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg');
     $params['attribute'] = array('description' => __('Limit result set to products with a specific attribute.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     $params['attribute_term'] = array('description' => __('Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'wp_parse_id_list', 'validate_callback' => 'rest_validate_request_arg');
     if (wc_tax_enabled()) {
         $params['tax_class'] = array('description' => __('Limit result set to products with a specific tax class.', 'woocommerce'), 'type' => 'string', 'enum' => array_map('sanitize_title', array_merge(array('standard'), WC_Tax::get_tax_classes())), 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     }
     $params['in_stock'] = array('description' => __('Limit result set to products in stock or out of stock.', 'woocommerce'), 'type' => 'boolean', 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg');
     $params['on_sale'] = array('description' => __('Limit result set to products on sale.', 'woocommerce'), 'type' => 'boolean', 'sanitize_callback' => 'wc_string_to_bool', 'validate_callback' => 'rest_validate_request_arg');
     $params['min_price'] = array('description' => __('Limit result set to products based on a minimum price.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     $params['max_price'] = array('description' => __('Limit result set to products based on a maximum price.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     return $params;
 }
<div class="panel-wrap product_data">

	<span class="type_box hidden"> &mdash;
		<label for="product-type">
			<select id="product-type" name="product-type">
				<optgroup label="<?php 
esc_attr_e('Product Type', 'woocommerce');
?>
">
				<?php 
foreach (wc_get_product_types() as $value => $label) {
    ?>
					<option value="<?php 
    echo esc_attr($value);
    ?>
" <?php 
    echo selected($product_object->get_type(), $value, false);
    ?>
><?php 
    echo esc_html($label);
    ?>
</option>
				<?php 
}
?>
				</optgroup>
			</select>
		</label>

		<?php 
foreach (self::get_product_type_options() as $key => $option) {
Exemplo n.º 8
0
 /**
  * Enqueue scripts.
  */
 public function admin_scripts()
 {
     global $wp_query, $post;
     $screen = get_current_screen();
     $screen_id = $screen ? $screen->id : '';
     $wc_screen_id = sanitize_title(__('WooCommerce', 'woocommerce'));
     $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     // Register scripts
     wp_register_script('woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip'), WC_VERSION);
     wp_register_script('jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array('jquery'), '2.70', true);
     wp_register_script('jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array('jquery'), WC_VERSION, true);
     wp_register_script('accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array('jquery'), '0.4.2');
     wp_register_script('round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array('jquery'), WC_VERSION);
     wp_register_script('wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array('jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip'), WC_VERSION);
     wp_register_script('zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array('jquery'), WC_VERSION);
     wp_register_script('qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array('jquery'), WC_VERSION);
     wp_register_script('stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array('jquery'), WC_VERSION);
     wp_register_script('serializejson', WC()->plugin_url() . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js', array('jquery'), '2.6.1');
     wp_register_script('flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array('jquery'), WC_VERSION);
     wp_register_script('flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array('jquery', 'flot'), WC_VERSION);
     wp_register_script('flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array('jquery', 'flot'), WC_VERSION);
     wp_register_script('flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array('jquery', 'flot'), WC_VERSION);
     wp_register_script('flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array('jquery', 'flot'), WC_VERSION);
     wp_register_script('wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array('jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui'), WC_VERSION);
     wp_register_script('wc-backbone-modal', WC()->plugin_url() . '/assets/js/admin/backbone-modal' . $suffix . '.js', array('underscore', 'backbone', 'wp-util'), WC_VERSION);
     wp_register_script('wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array('jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal'), WC_VERSION);
     wp_register_script('wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array('jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal'), WC_VERSION);
     wp_register_script('wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array('jquery', 'wp-util', 'underscore', 'backbone'), WC_VERSION);
     wp_register_script('select2', WC()->plugin_url() . '/assets/js/select2/select2' . $suffix . '.js', array('jquery'), '3.5.4');
     wp_register_script('wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array('jquery', 'select2'), WC_VERSION);
     wp_localize_script('wc-enhanced-select', 'wc_enhanced_select_params', array('i18n_matches_1' => _x('One result is available, press enter to select it.', 'enhanced select', 'woocommerce'), 'i18n_matches_n' => _x('%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce'), 'i18n_no_matches' => _x('No matches found', 'enhanced select', 'woocommerce'), 'i18n_ajax_error' => _x('Loading failed', 'enhanced select', 'woocommerce'), 'i18n_input_too_short_1' => _x('Please enter 1 or more characters', 'enhanced select', 'woocommerce'), 'i18n_input_too_short_n' => _x('Please enter %qty% or more characters', 'enhanced select', 'woocommerce'), 'i18n_input_too_long_1' => _x('Please delete 1 character', 'enhanced select', 'woocommerce'), 'i18n_input_too_long_n' => _x('Please delete %qty% characters', 'enhanced select', 'woocommerce'), 'i18n_selection_too_long_1' => _x('You can only select 1 item', 'enhanced select', 'woocommerce'), 'i18n_selection_too_long_n' => _x('You can only select %qty% items', 'enhanced select', 'woocommerce'), 'i18n_load_more' => _x('Loading more results&hellip;', 'enhanced select', 'woocommerce'), 'i18n_searching' => _x('Searching&hellip;', 'enhanced select', 'woocommerce'), 'ajax_url' => admin_url('admin-ajax.php'), 'search_products_nonce' => wp_create_nonce('search-products'), 'search_customers_nonce' => wp_create_nonce('search-customers')));
     // Accounting
     wp_localize_script('accounting', 'accounting_params', array('mon_decimal_point' => wc_get_price_decimal_separator()));
     // WooCommerce admin pages
     if (in_array($screen_id, wc_get_screen_ids())) {
         wp_enqueue_script('iris');
         wp_enqueue_script('woocommerce_admin');
         wp_enqueue_script('wc-enhanced-select');
         wp_enqueue_script('jquery-ui-sortable');
         wp_enqueue_script('jquery-ui-autocomplete');
         $locale = localeconv();
         $decimal = isset($locale['decimal_point']) ? $locale['decimal_point'] : '.';
         $params = array('i18n_decimal_error' => sprintf(__('Please enter in decimal (%s) format without thousand separators.', 'woocommerce'), $decimal), 'i18n_mon_decimal_error' => sprintf(__('Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce'), wc_get_price_decimal_separator()), 'i18n_country_iso_error' => __('Please enter in country code with two capital letters.', 'woocommerce'), 'i18_sale_less_than_regular_error' => __('Please enter in a value less than the regular price.', 'woocommerce'), 'decimal_point' => $decimal, 'mon_decimal_point' => wc_get_price_decimal_separator());
         wp_localize_script('woocommerce_admin', 'woocommerce_admin', $params);
     }
     // Edit product category pages
     if (in_array($screen_id, array('edit-product_cat'))) {
         wp_enqueue_media();
     }
     // Products
     if (in_array($screen_id, array('edit-product'))) {
         wp_register_script('woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array('jquery', 'woocommerce_admin'), WC_VERSION);
         wp_enqueue_script('woocommerce_quick-edit');
     }
     // Meta boxes
     if (in_array($screen_id, array('product', 'edit-product'))) {
         wp_enqueue_media();
         wp_register_script('wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array('wc-admin-meta-boxes', 'media-models'), WC_VERSION);
         wp_register_script('wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array('wc-admin-meta-boxes', 'serializejson', 'media-models'), WC_VERSION);
         wp_enqueue_script('wc-admin-product-meta-boxes');
         wp_enqueue_script('wc-admin-variation-meta-boxes');
         $params = array('post_id' => isset($post->ID) ? $post->ID : '', 'plugin_url' => WC()->plugin_url(), 'ajax_url' => admin_url('admin-ajax.php'), 'woocommerce_placeholder_img_src' => wc_placeholder_img_src(), 'add_variation_nonce' => wp_create_nonce('add-variation'), 'link_variation_nonce' => wp_create_nonce('link-variations'), 'delete_variations_nonce' => wp_create_nonce('delete-variations'), 'load_variations_nonce' => wp_create_nonce('load-variations'), 'save_variations_nonce' => wp_create_nonce('save-variations'), 'bulk_edit_variations_nonce' => wp_create_nonce('bulk-edit-variations'), 'i18n_link_all_variations' => esc_js(sprintf(__('Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max %d per run).', 'woocommerce'), defined('WC_MAX_LINKED_VARIATIONS') ? WC_MAX_LINKED_VARIATIONS : 50)), 'i18n_enter_a_value' => esc_js(__('Enter a value', 'woocommerce')), 'i18n_enter_menu_order' => esc_js(__('Variation menu order (determines position in the list of variations)', 'woocommerce')), 'i18n_enter_a_value_fixed_or_percent' => esc_js(__('Enter a value (fixed or %)', 'woocommerce')), 'i18n_delete_all_variations' => esc_js(__('Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce')), 'i18n_last_warning' => esc_js(__('Last warning, are you sure?', 'woocommerce')), 'i18n_choose_image' => esc_js(__('Choose an image', 'woocommerce')), 'i18n_set_image' => esc_js(__('Set variation image', 'woocommerce')), 'i18n_variation_added' => esc_js(__("variation added", 'woocommerce')), 'i18n_variations_added' => esc_js(__("variations added", 'woocommerce')), 'i18n_no_variations_added' => esc_js(__("No variations added", 'woocommerce')), 'i18n_remove_variation' => esc_js(__('Are you sure you want to remove this variation?', 'woocommerce')), 'i18n_scheduled_sale_start' => esc_js(__('Sale start date (YYYY-MM-DD format or leave blank)', 'woocommerce')), 'i18n_scheduled_sale_end' => esc_js(__('Sale end date (YYYY-MM-DD format or leave blank)', 'woocommerce')), 'i18n_edited_variations' => esc_js(__('Save changes before changing page?', 'woocommerce')), 'i18n_variation_count_single' => esc_js(__('%qty% variation', 'woocommerce')), 'i18n_variation_count_plural' => esc_js(__('%qty% variations', 'woocommerce')), 'variations_per_page' => absint(apply_filters('woocommerce_admin_meta_boxes_variations_per_page', 15)));
         wp_localize_script('wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params);
     }
     if (in_array(str_replace('edit-', '', $screen_id), wc_get_order_types('order-meta-boxes'))) {
         wp_register_script('wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array('wc-admin-meta-boxes', 'wc-backbone-modal'), WC_VERSION);
         wp_enqueue_script('wc-admin-order-meta-boxes');
         $params = array('countries' => json_encode(array_merge(WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states())), 'i18n_select_state_text' => esc_attr__('Select an option&hellip;', 'woocommerce'));
         wp_localize_script('wc-admin-order-meta-boxes', 'woocommerce_admin_meta_boxes_order', $params);
     }
     if (in_array($screen_id, array('shop_coupon', 'edit-shop_coupon'))) {
         wp_register_script('wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array('wc-admin-meta-boxes'), WC_VERSION);
         wp_enqueue_script('wc-admin-coupon-meta-boxes');
     }
     if (in_array(str_replace('edit-', '', $screen_id), array_merge(array('shop_coupon', 'product'), wc_get_order_types('order-meta-boxes')))) {
         $post_id = isset($post->ID) ? $post->ID : '';
         $currency = '';
         if ($post_id && in_array(get_post_type($post_id), wc_get_order_types('order-meta-boxes'))) {
             $order = wc_get_order($post_id);
             $currency = $order->get_order_currency();
         }
         $params = array('remove_item_notice' => __('Are you sure you want to remove the selected items? If you have previously reduced this item\'s stock, or this order was submitted by a customer, you will need to manually restore the item\'s stock.', 'woocommerce'), 'i18n_select_items' => __('Please select some items.', 'woocommerce'), 'i18n_do_refund' => __('Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce'), 'i18n_delete_refund' => __('Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce'), 'i18n_delete_tax' => __('Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce'), 'remove_item_meta' => __('Remove this item meta?', 'woocommerce'), 'remove_attribute' => __('Remove this attribute?', 'woocommerce'), 'name_label' => __('Name', 'woocommerce'), 'remove_label' => __('Remove', 'woocommerce'), 'click_to_toggle' => __('Click to toggle', 'woocommerce'), 'values_label' => __('Value(s)', 'woocommerce'), 'text_attribute_tip' => __('Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce'), 'visible_label' => __('Visible on the product page', 'woocommerce'), 'used_for_variations_label' => __('Used for variations', 'woocommerce'), 'new_attribute_prompt' => __('Enter a name for the new attribute term:', 'woocommerce'), 'calc_totals' => __('Calculate totals based on order items, discounts, and shipping?', 'woocommerce'), 'calc_line_taxes' => __('Calculate line taxes? This will calculate taxes based on the customers country. If no billing/shipping is set it will use the store base country.', 'woocommerce'), 'copy_billing' => __('Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce'), 'load_billing' => __('Load the customer\'s billing information? This will remove any currently entered billing information.', 'woocommerce'), 'load_shipping' => __('Load the customer\'s shipping information? This will remove any currently entered shipping information.', 'woocommerce'), 'featured_label' => __('Featured', 'woocommerce'), 'prices_include_tax' => esc_attr(get_option('woocommerce_prices_include_tax')), 'tax_based_on' => esc_attr(get_option('woocommerce_tax_based_on')), 'round_at_subtotal' => esc_attr(get_option('woocommerce_tax_round_at_subtotal')), 'no_customer_selected' => __('No customer selected', 'woocommerce'), 'plugin_url' => WC()->plugin_url(), 'ajax_url' => admin_url('admin-ajax.php'), 'order_item_nonce' => wp_create_nonce('order-item'), 'add_attribute_nonce' => wp_create_nonce('add-attribute'), 'save_attributes_nonce' => wp_create_nonce('save-attributes'), 'calc_totals_nonce' => wp_create_nonce('calc-totals'), 'get_customer_details_nonce' => wp_create_nonce('get-customer-details'), 'search_products_nonce' => wp_create_nonce('search-products'), 'grant_access_nonce' => wp_create_nonce('grant-access'), 'revoke_access_nonce' => wp_create_nonce('revoke-access'), 'add_order_note_nonce' => wp_create_nonce('add-order-note'), 'delete_order_note_nonce' => wp_create_nonce('delete-order-note'), 'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png', 'post_id' => isset($post->ID) ? $post->ID : '', 'base_country' => WC()->countries->get_base_country(), 'currency_format_num_decimals' => wc_get_price_decimals(), 'currency_format_symbol' => get_woocommerce_currency_symbol($currency), 'currency_format_decimal_sep' => esc_attr(wc_get_price_decimal_separator()), 'currency_format_thousand_sep' => esc_attr(wc_get_price_thousand_separator()), 'currency_format' => esc_attr(str_replace(array('%1$s', '%2$s'), array('%s', '%v'), get_woocommerce_price_format())), 'rounding_precision' => wc_get_rounding_precision(), 'tax_rounding_mode' => WC_TAX_ROUNDING_MODE, 'product_types' => array_unique(array_merge(array('simple', 'grouped', 'variable', 'external'), array_keys(wc_get_product_types()))), 'i18n_download_permission_fail' => __('Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce'), 'i18n_permission_revoke' => __('Are you sure you want to revoke access to this download?', 'woocommerce'), 'i18n_tax_rate_already_exists' => __('You cannot add the same tax rate twice!', 'woocommerce'), 'i18n_product_type_alert' => __('Your product has variations! Before changing the product type, it is a good idea to delete the variations to avoid errors in the stock reports.', 'woocommerce'), 'i18n_delete_note' => __('Are you sure you wish to delete this note? This action cannot be undone.', 'woocommerce'));
         wp_localize_script('wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params);
     }
     // Term ordering - only when sorting by term_order
     if ((strstr($screen_id, 'edit-pa_') || !empty($_GET['taxonomy']) && in_array($_GET['taxonomy'], apply_filters('woocommerce_sortable_taxonomies', array('product_cat')))) && !isset($_GET['orderby'])) {
         wp_register_script('woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array('jquery-ui-sortable'), WC_VERSION);
         wp_enqueue_script('woocommerce_term_ordering');
         $taxonomy = isset($_GET['taxonomy']) ? wc_clean($_GET['taxonomy']) : '';
         $woocommerce_term_order_params = array('taxonomy' => $taxonomy);
         wp_localize_script('woocommerce_term_ordering', 'woocommerce_term_ordering_params', $woocommerce_term_order_params);
     }
     // Product sorting - only when sorting by menu order on the products page
     if (current_user_can('edit_others_pages') && $screen_id == 'edit-product' && isset($wp_query->query['orderby']) && $wp_query->query['orderby'] == 'menu_order title') {
         wp_register_script('woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array('jquery-ui-sortable'), WC_VERSION, true);
         wp_enqueue_script('woocommerce_product_ordering');
     }
     // Reports Pages
     if (in_array($screen_id, apply_filters('woocommerce_reports_screen_ids', array($wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard')))) {
         wp_register_script('wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array('jquery', 'jquery-ui-datepicker'), WC_VERSION);
         wp_enqueue_script('wc-reports');
         wp_enqueue_script('flot');
         wp_enqueue_script('flot-resize');
         wp_enqueue_script('flot-time');
         wp_enqueue_script('flot-pie');
         wp_enqueue_script('flot-stack');
     }
     // API settings
     if ($wc_screen_id . '_page_wc-settings' === $screen_id && isset($_GET['section']) && 'keys' == $_GET['section']) {
         wp_register_script('wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array('jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'zeroclipboard'), WC_VERSION, true);
         wp_enqueue_script('wc-api-keys');
         wp_localize_script('wc-api-keys', 'woocommerce_admin_api_keys', array('ajax_url' => admin_url('admin-ajax.php'), 'update_api_nonce' => wp_create_nonce('update-api-key'), 'clipboard_failed' => esc_html__('Copying to clipboard failed. Please press Ctrl/Cmd+C to copy.', 'woocommerce')));
     }
     // System status
     if ($wc_screen_id . '_page_wc-status' === $screen_id) {
         wp_enqueue_script('zeroclipboard');
     }
     if (in_array($screen_id, array('user-edit', 'profile'))) {
         wp_register_script('wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array('jquery', 'wc-enhanced-select'), WC_VERSION, true);
         wp_enqueue_script('wc-users');
         wp_localize_script('wc-users', 'wc_users_params', array('countries' => json_encode(array_merge(WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states())), 'i18n_select_state_text' => esc_attr__('Select an option&hellip;', 'woocommerce')));
     }
 }
 /**
  * Get the query params for collections of attachments.
  *
  * @return array
  */
 public function get_collection_params()
 {
     $params = parent::get_collection_params();
     $params['slug'] = array('description' => __('Limit result set to products with a specific slug.', 'woocommerce', 'woocommerce'), 'type' => 'string', 'validate_callback' => 'rest_validate_request_arg');
     $params['status'] = array('default' => 'any', 'description' => __('Limit result set to products assigned a specific status.', 'woocommerce'), 'type' => 'string', 'enum' => array_merge(array('any'), array_keys(get_post_statuses())), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg');
     $params['type'] = array('description' => __('Limit result set to products assigned a specific type.', 'woocommerce'), 'type' => 'string', 'enum' => array_keys(wc_get_product_types()), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg');
     $params['category'] = array('description' => __('Limit result set to products assigned a specific category.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     $params['tag'] = array('description' => __('Limit result set to products assigned a specific tag.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     $params['shipping_class'] = array('description' => __('Limit result set to products assigned a specific shipping class.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     $params['attribute'] = array('description' => __('Limit result set to products with a specific attribute.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     $params['attribute_term'] = array('description' => __('Limit result set to products with a specific attribute term (required an assigned attribute).', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     $params['sku'] = array('description' => __('Limit result set to products with a specific SKU.', 'woocommerce'), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg');
     return $params;
 }
Exemplo n.º 10
0
 /**
  * Test wc_get_product_types()
  *
  * @since 2.3
  */
 public function test_wc_get_product_types()
 {
     $product_types = (array) apply_filters('product_type_selector', array('simple' => __('Simple product', 'woocommerce'), 'grouped' => __('Grouped product', 'woocommerce'), 'external' => __('External/Affiliate product', 'woocommerce'), 'variable' => __('Variable product', 'woocommerce')));
     $this->assertEquals($product_types, wc_get_product_types());
 }
Exemplo n.º 11
0
 /**
  * Edit a product
  *
  * @since 2.2
  * @param int $id the product ID
  * @param array $data
  * @return array
  */
 public function edit_product($id, $data)
 {
     $data = isset($data['product']) ? $data['product'] : array();
     $id = $this->validate_request($id, 'product', 'edit');
     if (is_wp_error($id)) {
         return $id;
     }
     $data = apply_filters('woocommerce_api_edit_product_data', $data, $this);
     // Product name.
     if (isset($data['title'])) {
         wp_update_post(array('ID' => $id, 'post_title' => wc_clean($data['title'])));
     }
     // Product status.
     if (isset($data['status'])) {
         wp_update_post(array('ID' => $id, 'post_status' => wc_clean($data['status'])));
     }
     // Product short description.
     if (isset($data['short_description'])) {
         wp_update_post(array('ID' => $id, 'post_excerpt' => wc_clean($data['short_description'])));
     }
     // Product description.
     if (isset($data['description'])) {
         wp_update_post(array('ID' => $id, 'post_content' => wc_clean($data['description'])));
     }
     // Validate the product type
     if (isset($data['type']) && !in_array(wc_clean($data['type']), array_keys(wc_get_product_types()))) {
         return new WP_Error('woocommerce_api_invalid_product_type', sprintf(__('Invalid product type - the product type must be any of these: %s', 'woocommerce'), implode(', ', array_keys(wc_get_product_types()))), array('status' => 400));
     }
     // Check for featured/gallery images, upload it and set it
     if (isset($data['images'])) {
         $images = $this->save_product_images($id, $data['images']);
         if (is_wp_error($images)) {
             return $images;
         }
     }
     // Save product meta fields
     $meta = $this->save_product_meta($id, $data);
     if (is_wp_error($meta)) {
         return $meta;
     }
     // Save variations
     if (isset($data['type']) && 'variable' == $data['type'] && isset($data['variations']) && is_array($data['variations'])) {
         $variations = $this->save_variations($id, $data);
         if (is_wp_error($variations)) {
             return $variations;
         }
     }
     do_action('woocommerce_api_edit_product', $id, $data);
     // Clear cache/transients
     wc_delete_product_transients($id);
     return $this->get_product($id);
 }
 function add_settings()
 {
     $product_cats = array();
     $product_categories = get_terms('product_cat', 'orderby=name&hide_empty=0');
     foreach ($product_categories as $product_category) {
         $product_cats[$product_category->term_id] = $product_category->name;
     }
     $products = wcj_get_products();
     $settings = array(array('title' => __('Custom Price Labels - Globally', 'woocommerce-jetpack'), 'type' => 'title', 'desc' => __('This section lets you set price labels for all products globally.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_options'), array('title' => __('Add before the price', 'woocommerce-jetpack'), 'desc_tip' => __('Enter text to add before all products prices. Leave blank to disable.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_add_before_text', 'default' => '', 'type' => 'textarea', 'desc' => apply_filters('booster_get_message', '', 'desc'), 'custom_attributes' => apply_filters('booster_get_message', '', 'readonly'), 'css' => 'width:30%;min-width:300px;'), array('title' => __('Add after the price', 'woocommerce-jetpack'), 'desc_tip' => __('Enter text to add after all products prices. Leave blank to disable.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_add_after_text', 'default' => '', 'type' => 'textarea', 'css' => 'width:30%;min-width:300px;'), array('title' => __('Add between regular and sale prices', 'woocommerce-jetpack'), 'desc_tip' => __('Enter text to add between regular and sale prices. Leave blank to disable.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_between_regular_and_sale_text', 'default' => '', 'type' => 'textarea', 'desc' => apply_filters('booster_get_message', '', 'desc'), 'custom_attributes' => apply_filters('booster_get_message', '', 'readonly'), 'css' => 'width:30%;min-width:300px;'), array('title' => __('Remove from price', 'woocommerce-jetpack'), 'desc_tip' => __('Enter text to remove from all products prices. Leave blank to disable.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_remove_text', 'default' => '', 'type' => 'textarea', 'desc' => apply_filters('booster_get_message', '', 'desc'), 'custom_attributes' => apply_filters('booster_get_message', '', 'readonly'), 'css' => 'width:30%;min-width:300px;'), array('title' => __('Replace in price', 'woocommerce-jetpack'), 'desc_tip' => __('Enter text to replace in all products prices. Leave blank to disable.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_replace_text', 'default' => '', 'type' => 'textarea', 'desc' => apply_filters('booster_get_message', '', 'desc'), 'custom_attributes' => apply_filters('booster_get_message', '', 'readonly'), 'css' => 'width:30%;min-width:300px;'), array('title' => '', 'desc_tip' => __('Enter text to replace with. Leave blank to disable.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_replace_with_text', 'default' => '', 'type' => 'textarea', 'desc' => apply_filters('booster_get_message', '', 'desc'), 'custom_attributes' => apply_filters('booster_get_message', '', 'readonly'), 'css' => 'width:30%;min-width:300px;'), array('title' => __('Products - Include', 'woocommerce-jetpack'), 'desc_tip' => __('Apply global price labels only for selected products. Leave blank to disable the option.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_products_incl', 'default' => '', 'type' => 'multiselect', 'class' => 'chosen_select', 'css' => 'width: 450px;', 'options' => $products), array('title' => __('Products - Exclude', 'woocommerce-jetpack'), 'desc_tip' => __('Do not apply global price labels only for selected products. Leave blank to disable the option.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_products_excl', 'default' => '', 'type' => 'multiselect', 'class' => 'chosen_select', 'css' => 'width: 450px;', 'options' => $products), array('title' => __('Product Categories - Include', 'woocommerce-jetpack'), 'desc_tip' => __('Apply global price labels only for selected product categories. Leave blank to disable the option.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_product_cats_incl', 'default' => '', 'type' => 'multiselect', 'class' => 'chosen_select', 'css' => 'width: 450px;', 'options' => $product_cats), array('title' => __('Product Categories - Exclude', 'woocommerce-jetpack'), 'desc_tip' => __('Do not apply global price labels only for selected product categories. Leave blank to disable the option.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_product_cats_excl', 'default' => '', 'type' => 'multiselect', 'class' => 'chosen_select', 'css' => 'width: 450px;', 'options' => $product_cats), array('title' => __('Product Types - Include', 'woocommerce-jetpack'), 'desc_tip' => __('Apply global price labels only for selected product types. Leave blank to disable the option.', 'woocommerce-jetpack'), 'id' => 'wcj_global_price_labels_product_types_incl', 'default' => '', 'type' => 'multiselect', 'class' => 'chosen_select', 'css' => 'width: 450px;', 'options' => array_merge(wc_get_product_types(), array('variation' => __('Variable product\'s variation', 'woocommerce-jetpack')))), array('type' => 'sectionend', 'id' => 'wcj_global_price_labels_options'), array('title' => __('Custom Price Labels - Per Product', 'woocommerce-jetpack'), 'type' => 'title', 'id' => 'wcj_local_price_labels_options'), array('title' => __('Enable', 'woocommerce-jetpack'), 'desc' => __('This will add metaboxes to each product\'s admin edit page.', 'woocommerce-jetpack'), 'id' => 'wcj_local_price_labels_enabled', 'default' => 'yes', 'type' => 'checkbox'), array('type' => 'sectionend', 'id' => 'wcj_local_price_labels_options'));
     return $settings;
 }
 public function get_display_settings()
 {
     $digital_type_options = array_merge(array('downloadable' => __('Downloadable Product', 'woocommerce-germanized'), 'virtual' => __('Virtual Product', 'woocommerce-germanized')), wc_get_product_types());
     $settings = array(array('title' => __('General', 'woocommerce-germanized'), 'type' => 'title', 'id' => 'general_options'), array('title' => __('Add to Cart', 'woocommerce-germanized'), 'desc' => __('Show add to cart button on listings?', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_listings_add_to_cart', 'default' => 'yes', 'type' => 'checkbox', 'desc_tip' => __('unset this option if you don\'t want to show the add to cart button within the product listings', 'woocommerce-germanized')), array('title' => __('Link to Details', 'woocommerce-germanized'), 'desc' => __('Want to link to product details page instead of add to cart within listings?', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_listings_link_details', 'default' => 'no', 'type' => 'checkbox', 'desc_tip' => __('Decide whether you like to link to your product\'s details page instead of displaying an add to cart button within product listings.', 'woocommerce-germanized')), array('title' => __('Product Details Text', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_listings_link_details_text', 'default' => __('Details', 'woocommerce-germanized'), 'type' => 'text', 'desc_tip' => __('If you have chosen to link to product details page instead of add to cart URL you may want to change the button text.', 'woocommerce-germanized'), 'css' => 'min-width:300px;'), array('title' => __('Notice Footer', 'woocommerce-germanized'), 'desc' => __('Show a global VAT notice within footer', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_footer_vat_notice', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'start'), array('desc' => __('Show a global sale price notice within footer', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_footer_sale_price_notice', 'type' => 'checkbox', 'default' => 'no', 'checkboxgroup' => 'end'), array('type' => 'sectionend', 'id' => 'general_options'), array('title' => __('Products', 'woocommerce-germanized'), 'type' => 'title', 'id' => 'product_options'), array('title' => __('Show within Product Listings', 'woocommerce-germanized'), 'desc' => __('Shipping Costs notice', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_listings_shipping_costs', 'type' => 'checkbox', 'default' => 'yes', 'checkboxgroup' => 'start'), array('desc' => __('Tax Info', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_listings_tax_info', 'type' => 'checkbox', 'default' => 'yes', 'checkboxgroup' => ''), array('desc' => __('Base Price', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_listings_unit_price', 'type' => 'checkbox', 'default' => 'yes', 'checkboxgroup' => ''), array('desc' => __('Product Units', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_listings_product_units', 'type' => 'checkbox', 'default' => 'no', 'checkboxgroup' => ''), array('desc' => __('Delivery Time Notice', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_listings_delivery_time', 'type' => 'checkbox', 'default' => 'yes', 'checkboxgroup' => 'end'), array('title' => __('Show on Product Detail Page', 'woocommerce-germanized'), 'desc' => __('Shipping Costs notice', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_product_detail_shipping_costs', 'type' => 'checkbox', 'default' => 'yes', 'checkboxgroup' => 'start'), array('desc' => __('Tax Info', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_product_detail_tax_info', 'type' => 'checkbox', 'default' => 'yes', 'checkboxgroup' => ''), array('desc' => __('Base Price', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_product_detail_unit_price', 'type' => 'checkbox', 'default' => 'yes', 'checkboxgroup' => ''), array('desc' => __('Product Units', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_product_detail_product_units', 'type' => 'checkbox', 'default' => 'no', 'checkboxgroup' => ''), array('desc' => __('Delivery Time Notice', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_product_detail_delivery_time', 'type' => 'checkbox', 'default' => 'yes', 'checkboxgroup' => 'end'), array('title' => __('Shipping Costs for Virtual', 'woocommerce-germanized'), 'desc' => __('Select this option if you want to display shipping costs notice for virtual products.', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_shipping_costs_virtual', 'type' => 'checkbox', 'default' => 'no'), array('type' => 'sectionend', 'id' => 'product_options'), array('title' => __('Base Price', 'woocommerce-germanized'), 'type' => 'title', 'id' => 'unit_price_options'), array('title' => __('Base Price Text', 'woocommerce-germanized'), 'desc' => __('This text will be used to display the base price. Use {price} to insert the price. If you want to specifically format base price output use {base}, {unit} and {base_price} as placeholders.', 'woocommerce-germanized'), 'desc_tip' => true, 'id' => 'woocommerce_gzd_unit_price_text', 'type' => 'text', 'css' => 'min-width:300px;', 'default' => __('{price}', 'woocommerce-germanized')), array('title' => __('Product Units Text', 'woocommerce-germanized'), 'desc' => __('This text will be used to display the product units. Use {product_units} to insert the amount of product units. Use {unit} to insert the unit. Optionally display the formatted unit price with {unit_price}.', 'woocommerce-germanized'), 'desc_tip' => true, 'id' => 'woocommerce_gzd_product_units_text', 'type' => 'text', 'css' => 'min-width:300px;', 'default' => __('Product contains: {product_units} {unit}', 'woocommerce-germanized')), array('type' => 'sectionend', 'id' => 'unit_price_options'), array('title' => __('Checkout & Cart', 'woocommerce-germanized'), 'type' => 'title', 'id' => 'checkout_options'), version_compare(WC()->version, '2.3', '>=') ? array('title' => __('Fallback Mode', 'woocommerce-germanized'), 'desc' => __('Enable to make sure default checkout template is not being overriden by theme.', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_checkout_fallback', 'default' => 'no', 'type' => 'checkbox', 'desc_tip' => __('If you are facing problems within your checkout e.g. legally relevant data is not showing (terms, delivery time, unit price etc.) your theme seems to be incompatible (not using default WooCommerce hooks and filters). As a workaround you may use this fallback which ensures default review-order.php and form-checkout.php is used.', 'woocommerce-germanized')) : array(), array('title' => __('Force free shipping', 'woocommerce-germanized'), 'desc' => __('Force free shipping method if available?', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_checkout_free_shipping_select', 'default' => 'no', 'type' => 'checkbox', 'desc_tip' => __('By default WooCommerce will let customers choose other shipping methods than free shipping (if available). This option will force free shipping if available.', 'woocommerce-germanized')), array('title' => __('Hide taxes estimated', 'woocommerce-germanized'), 'desc' => __('Do you want to hide the "taxes and shipping estimated" text from your cart?', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_hide_cart_tax_estimated', 'default' => 'yes', 'type' => 'checkbox', 'desc_tip' => __('By default WooCommerce adds a "taxes and shipping estimated" text to your cart. This might puzzle your customers and may not meet german law.', 'woocommerce-germanized')), array('title' => __('Show Thumbnails', 'woocommerce-germanized'), 'desc' => __('Show product thumbnails on checkout page?', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_checkout_thumbnails', 'default' => 'yes', 'type' => 'checkbox', 'desc_tip' => __('Uncheck if you don\'t want to show your product thumbnails within checkout table.', 'woocommerce-germanized')), array('title' => __('Hide Shipping Select', 'woocommerce-germanized'), 'desc' => __('Hide shipping rate selection from checkout?', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_checkout_shipping_rate_select', 'default' => 'yes', 'type' => 'checkbox', 'desc_tip' => __('This option will hide shipping rate selection from checkout. By then customers will only be able to change their shipping rate on cart page.', 'woocommerce-germanized')), array('title' => __('Show back to cart button', 'woocommerce-germanized'), 'desc' => __('Show back to cart button within your checkout table?', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_checkout_back_to_cart_button', 'default' => 'no', 'type' => 'checkbox', 'desc_tip' => __('This button may let your customer edit their order before submitting. Some people state that this button should be hidden to avoid legal problems.', 'woocommerce-germanized')), array('title' => __('Show edit data notice', 'woocommerce-germanized'), 'desc' => __('Show a "check-your-entries" notice to the user?', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_checkout_edit_data_notice', 'default' => 'no', 'type' => 'checkbox', 'desc_tip' => __('This notice will be added right before the order comments field.', 'woocommerce-germanized')), array('title' => __('Checkout Table Color', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_checkout_table_color', 'desc_tip' => __('Choose the color of your checkout product table. This table should be highlighted within your checkout page.', 'woocommerce-germanized'), 'default' => '#eeeeee', 'type' => 'color'), array('title' => __('Checkout Legal Display', 'woocommerce-germanized'), 'desc' => __('Use Text without Checkbox', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_display_checkout_legal_no_checkbox', 'desc_tip' => __('This version will remove checkboxes from Checkout and display a text instead. This seems to be legally compliant (Zalando & Co are using this option).', 'woocommerce-germanized'), 'default' => 'no', 'type' => 'checkbox'), array('title' => __('Legal Text', 'woocommerce-germanized'), 'desc' => __('Choose a Plain Text which will be shown right above checkout submit button. Use {term_link}{/term_link}, {data_security_link}{/data_security_link}, {revocation_link}{/revocation_link} as Placeholders for the links to legal pages.', 'woocommerce-germanized'), 'desc_tip' => true, 'default' => __('With your order, you agree to have read and understood our {term_link}Terms and Conditions{/term_link} and your {revocation_link}Right of Recission{/revocation_link}.', 'woocommerce-germanized'), 'css' => 'width:100%; height: 65px;', 'id' => 'woocommerce_gzd_checkout_legal_text', 'type' => 'textarea'), array('title' => __('Legal Text Error', 'woocommerce-germanized'), 'desc' => __('If you have chosen to use checkbox validation please choose a error message which will be shown if the user doesn\'t check checkbox. Use {term_link}{/term_link}, {data_security_link}{/data_security_link}, {revocation_link}{/revocation_link} as Placeholders for the links to legal pages.', 'woocommerce-germanized'), 'desc_tip' => true, 'default' => __('To finish the order you have to accept to our {term_link}Terms and Conditions{/term_link} and {revocation_link}Right of Recission{/revocation_link}.', 'woocommerce-germanized'), 'css' => 'width:100%; height: 65px;', 'id' => 'woocommerce_gzd_checkout_legal_text_error', 'type' => 'textarea'), array('title' => __('Show digital notice', 'woocommerce-germanized'), 'desc' => __('Show checkbox for digital products.', 'woocommerce-germanized'), 'desc_tip' => __('Disable this option if you want your customers to obtain their right of recission even if digital products are being bought.', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_checkout_legal_digital_checkbox', 'default' => 'yes', 'type' => 'checkbox'), array('title' => __('Digital Product types', 'woocommerce-germanized'), 'desc' => __('Select product types for which the loss of recission notice is shown. Product types like "simple product" may be redudant because they include virtual and downloadable products.', 'woocommerce-germanized'), 'desc_tip' => true, 'id' => 'woocommerce_gzd_checkout_legal_digital_types', 'default' => array('downloadable'), 'class' => 'chosen_select', 'options' => $digital_type_options, 'type' => 'multiselect'), array('title' => __('Legal Digital Text', 'woocommerce-germanized'), 'desc' => __('Choose a Plain Text which will be shown right above checkout submit button if a user has picked a digital product. See legal text option for possible placeholders.', 'woocommerce-germanized'), 'desc_tip' => true, 'default' => __('For digital products: I strongly agree that the execution of the agreement starts before the revocation period has expired. I am aware that my right of withdrawal ceases with the beginning of the agreement.', 'woocommerce-germanized'), 'css' => 'width:100%; height: 65px;', 'id' => 'woocommerce_gzd_checkout_legal_text_digital', 'type' => 'textarea'), array('title' => __('Legal Digital Error', 'woocommerce-germanized'), 'desc' => __('This text will be shown as error message if customer has not checked the corresponding checkbox. See legal text option for possible placeholders.', 'woocommerce-germanized'), 'desc_tip' => true, 'default' => __('To retrieve direct access to digital content you have to agree to the loss of your right of withdrawal.', 'woocommerce-germanized'), 'css' => 'width:100%; height: 65px;', 'id' => 'woocommerce_gzd_checkout_legal_text_digital_error', 'type' => 'textarea'), array('title' => __('Digital Confirmation Notice', 'woocommerce-germanized'), 'desc' => __('This text will be appended to your order processing email if the order contains digital products. Use placeholders {link}{/link} to insert link to right of withdrawal page.', 'woocommerce-germanized'), 'desc_tip' => true, 'id' => 'woocommerce_gzd_order_confirmation_legal_digital_notice', 'default' => __('Furthermore you have expressly agreed to start the performance of the contract for digital items (e.g. downloads) before expiry of the withdrawal period. I have noted to lose my {link}right of withdrawal{/link} with the beginning of the performance of the contract.', 'woocommerce-germanized'), 'type' => 'textarea', 'css' => 'width:100%; height: 65px;'), array('title' => __('Pay now Button', 'woocommerce-germanized'), 'desc' => __('Add a pay now button to emails and order success page.', 'woocommerce-germanized'), 'desc_tip' => __('Add a pay now button to order confirmation email and order success page if the order awaits payment (PayPal etc).', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_order_pay_now_button', 'type' => 'checkbox', 'default' => 'yes'), array('title' => __('Order Success Text', 'woocommerce-germanized'), 'desc' => __('Choose a custom text to display on order success page.', 'woocommerce-germanized'), 'desc_tip' => true, 'css' => 'width:100%; height: 65px;', 'id' => 'woocommerce_gzd_order_success_text', 'type' => 'textarea'), array('title' => __('Order Success Data', 'woocommerce-germanized'), 'desc' => __('Hide product table and customer data on order success page', 'woocommerce-germanized'), 'id' => 'woocommerce_gzd_hide_order_success_details', 'type' => 'checkbox', 'default' => 'no'), array('type' => 'sectionend', 'id' => 'checkout_options'));
     return apply_filters('woocommerce_germanized_settings_display', $settings);
 }
 /**
  * Add a new product
  *
  * @since 2.2
  * @param array $data posted data
  * @return array
  */
 public function add_product($data)
 {
     // Check permisions
     if (!current_user_can('publish_products')) {
         return new WP_Error('woocommerce_api_user_cannot_create_product', __('You do not have permission to create products', 'woocommerce'), array('status' => 401));
     }
     // Check if product title is specified
     if (!isset($data['title'])) {
         return new WP_Error('woocommerce_api_missing_product_title', sprintf(__('Missing parameter %s'), 'title'), array('status' => 400));
     }
     // Check product type
     if (!isset($data['type'])) {
         $data['type'] = 'simple';
     } else {
         if ($data['type'] == 'booking') {
         } elseif ($data['type'] == 'virtual') {
         } elseif (!in_array(wc_clean($data['type']), array_keys(wc_get_product_types()))) {
             return new WP_Error('woocommerce_api_invalid_product_type', sprintf(__('Invalid product type - the product type must be any of these: %s', 'woocommerce'), implode(', ', array_keys(wc_get_product_types()))), array('status' => 400));
         }
     }
     $new_product = array('post_title' => $data['title'], 'post_status' => isset($data['status']) ? wc_clean($data['status']) : 'publish', 'post_type' => 'product', 'post_excerpt' => isset($data['short_description']) ? wc_clean($data['short_description']) : '', 'post_content' => isset($data['description']) ? wc_clean($data['description']) : '', 'post_author' => get_current_user_id());
     $product_id = wp_insert_post($new_product, true);
     if (is_wp_error($product_id)) {
         return new WP_Error('woocommerce_api_cannot_create_product', $product_id->get_error_message(), array('status' => 400));
     }
     if (isset($data['sku'])) {
         update_post_meta($product_id, '_sku', $data['sku'], true);
     }
     if (isset($data['type'])) {
         wp_set_object_terms($product_id, $data['type'], 'product_type');
     }
     if (isset($data['regular_price'])) {
         # code...
         update_post_meta($product_id, '_regular_price', $data['regular_price'], true);
         update_post_meta($product_id, '_price', $data['regular_price'], true);
     }
     if (isset($data['managing_stock'])) {
         # code...
         update_post_meta($product_id, '_manage_stock', 'yes');
     }
     if (isset($data['stock'])) {
         # code...
         update_post_meta($product_id, '_stock', $data['stock']);
     }
     if (isset($data['visibility'])) {
         # code...
         update_post_meta($product_id, '_visibility', $data['visibility']);
     }
     // Check for featured/gallery images, upload it and set it
     if (isset($data['images'])) {
         $gallery_ids = array();
         foreach ($data['images'] as $product_image) {
             if (isset($product_image['position']) && isset($product_image['src']) && $product_image['position'] == 0) {
                 $upload = $this->upload_product_image(wc_clean($product_image['src']));
                 if (is_wp_error($upload)) {
                     return new WP_Error('woocommerce_api_cannot_upload_product_image', $upload->get_error_message(), array('status' => 400));
                 }
                 $attachment_id = $this->set_product_image_as_attachment($upload, $product_id);
                 set_post_thumbnail($product_id, $attachment_id);
             } else {
                 if (isset($product_image['src'])) {
                     /*
                     					$upload = $this->upload_product_image( wc_clean( $product_image['src'] ) );
                     							//generate metadata
                     							//wp_generate_attachment_metadata( $attachmentid, $upload['file'] );
                     					if ( is_wp_error( $upload ) ) {
                     						return new WP_Error( 'woocommerce_api_cannot_upload_product_image', $upload->get_error_message(), array( 'status' => 400 ) );
                     					}
                     					$attachment_id = $this->set_product_image_as_attachment( $upload, $product_id );
                     					
                     
                     					$upload = $this->upload_product_image( wc_clean( $product_image['src'] ) );
                     */
                     // Upload an Image
                     $image = media_sideload_image($product_image['src'], $product_id);
                     // Remove any unwanted HTML, keep just a plain URL (or whatever is in the image src="..." )
                     $image = preg_replace('/.*(?<=src=["\'])([^"\']*)(?=["\']).*/', '$1', $image);
                     // Get the Attachment ID
                     $attachment_id = $this->get_attachment_id_from_src($image);
                     set_post_thumbnail($product_id, $attachment_id);
                 }
             }
         }
     }
     return $product_id;
 }