PageRenderTime 63ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/wordpress/wp-content/plugins/woocommerce/admin/post-types/writepanels/writepanel-product_data.php

https://github.com/hurricane-voronin/eshop
PHP | 1088 lines | 739 code | 250 blank | 99 comment | 131 complexity | 28b23c750fcdcda59cb8b72af2975aba MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Product Data
  4. *
  5. * Function for displaying the product data meta boxes
  6. *
  7. * @author WooThemes
  8. * @category Admin
  9. * @package WooCommerce/Admin/WritePanels
  10. * @version 2.0.0
  11. */
  12. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  13. /** Variable products */
  14. require_once( 'writepanel-product-type-variable.php' );
  15. /**
  16. * Display the product data meta box.
  17. *
  18. * Displays the product data box, tabbed, with several panels covering price, stock etc.
  19. *
  20. * @access public
  21. * @return void
  22. */
  23. function woocommerce_product_data_box() {
  24. global $post, $wpdb, $thepostid, $woocommerce;
  25. wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
  26. $thepostid = $post->ID;
  27. if ( $terms = wp_get_object_terms( $post->ID, 'product_type' ) )
  28. $product_type = sanitize_title( current( $terms )->name );
  29. else
  30. $product_type = 'simple';
  31. $product_type_selector = apply_filters( 'product_type_selector', array(
  32. 'simple' => __( 'Simple product', 'woocommerce' ),
  33. 'grouped' => __( 'Grouped product', 'woocommerce' ),
  34. 'external' => __( 'External/Affiliate product', 'woocommerce' )
  35. ), $product_type );
  36. $type_box = '<label for="product-type"><select id="product-type" name="product-type"><optgroup label="' . __( 'Product Type', 'woocommerce' ) . '">';
  37. foreach ( $product_type_selector as $value => $label )
  38. $type_box .= '<option value="' . esc_attr( $value ) . '" ' . selected( $product_type, $value, false ) .'>' . esc_html( $label ) . '</option>';
  39. $type_box .= '</optgroup></select></label>';
  40. $product_type_options = apply_filters('product_type_options', array(
  41. 'virtual' => array(
  42. 'id' => '_virtual',
  43. 'wrapper_class' => 'show_if_simple',
  44. 'label' => __( 'Virtual', 'woocommerce' ),
  45. 'description' => __( 'Virtual products are intangible and aren\'t shipped.', 'woocommerce' )
  46. ),
  47. 'downloadable' => array(
  48. 'id' => '_downloadable',
  49. 'wrapper_class' => 'show_if_simple',
  50. 'label' => __( 'Downloadable', 'woocommerce' ),
  51. 'description' => __( 'Downloadable products give access to a file upon purchase.', 'woocommerce' )
  52. )
  53. ) );
  54. foreach ( $product_type_options as $key => $option ) {
  55. $selected_value = get_post_meta( $post->ID, '_' . $key, true );
  56. $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>';
  57. }
  58. ?>
  59. <div class="panel-wrap product_data">
  60. <span class="type_box"> &mdash; <?php echo $type_box; ?></span>
  61. <div class="wc-tabs-back"></div>
  62. <ul class="product_data_tabs wc-tabs" style="display:none;">
  63. <li class="active general_options hide_if_grouped"><a href="#general_product_data"><?php _e( 'General', 'woocommerce' ); ?></a></li>
  64. <li class="inventory_tab show_if_simple show_if_variable show_if_grouped inventory_options"><a href="#inventory_product_data"><?php _e( 'Inventory', 'woocommerce' ); ?></a></li>
  65. <li class="shipping_tab hide_if_virtual shipping_options hide_if_grouped hide_if_external"><a href="#shipping_product_data"><?php _e( 'Shipping', 'woocommerce' ); ?></a></li>
  66. <li class="linked_product_tab linked_product_options"><a href="#linked_product_data"><?php _e( 'Linked Products', 'woocommerce' ); ?></a></li>
  67. <li class="attributes_tab attribute_options"><a href="#woocommerce_attributes"><?php _e( 'Attributes', 'woocommerce' ); ?></a></li>
  68. <li class="advanced_tab advanced_options"><a href="#advanced_product_data"><?php _e( 'Advanced', 'woocommerce' ); ?></a></li>
  69. <?php do_action( 'woocommerce_product_write_panel_tabs' ); ?>
  70. </ul>
  71. <div id="general_product_data" class="panel woocommerce_options_panel"><?php
  72. echo '<div class="options_group hide_if_grouped">';
  73. // SKU
  74. if( get_option('woocommerce_enable_sku', true) !== 'no' )
  75. 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' ) ) );
  76. else
  77. echo '<input type="hidden" name="_sku" value="' . esc_attr( get_post_meta( $thepostid, '_sku', true ) ) . '" />';
  78. do_action('woocommerce_product_options_sku');
  79. echo '</div>';
  80. echo '<div class="options_group show_if_external">';
  81. // External URL
  82. woocommerce_wp_text_input( array( 'id' => '_product_url', 'label' => __( 'Product URL', 'woocommerce' ), 'placeholder' => 'http://', 'description' => __( 'Enter the external URL to the product.', 'woocommerce' ) ) );
  83. // Button text
  84. 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' ) ) );
  85. echo '</div>';
  86. echo '<div class="options_group pricing show_if_simple show_if_external">';
  87. // Price
  88. woocommerce_wp_text_input( array( 'id' => '_regular_price', 'class' => 'wc_input_price short', 'label' => __( 'Regular Price', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')', 'type' => 'number', 'custom_attributes' => array(
  89. 'step' => 'any',
  90. 'min' => '0'
  91. ) ) );
  92. // Special Price
  93. woocommerce_wp_text_input( array( 'id' => '_sale_price', 'class' => 'wc_input_price short', 'label' => __( 'Sale Price', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')', 'description' => '<a href="#" class="sale_schedule">' . __( 'Schedule', 'woocommerce' ) . '</a>', 'type' => 'number', 'custom_attributes' => array(
  94. 'step' => 'any',
  95. 'min' => '0'
  96. ) ) );
  97. // Special Price date range
  98. $sale_price_dates_from = ( $date = get_post_meta( $thepostid, '_sale_price_dates_from', true ) ) ? date_i18n( 'Y-m-d', $date ) : '';
  99. $sale_price_dates_to = ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) ? date_i18n( 'Y-m-d', $date ) : '';
  100. echo ' <p class="form-field sale_price_dates_fields">
  101. <label for="_sale_price_dates_from">' . __( 'Sale Price Dates', 'woocommerce' ) . '</label>
  102. <input type="text" class="short" name="_sale_price_dates_from" id="_sale_price_dates_from" value="' . $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])" />
  103. <input type="text" class="short" name="_sale_price_dates_to" id="_sale_price_dates_to" value="' . $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])" />
  104. <a href="#" class="cancel_sale_schedule">'. __( 'Cancel', 'woocommerce' ) .'</a>
  105. </p>';
  106. do_action( 'woocommerce_product_options_pricing' );
  107. echo '</div>';
  108. echo '<div class="options_group show_if_downloadable">';
  109. // File URL
  110. $file_paths = get_post_meta( $post->ID, '_file_paths', true );
  111. if ( is_array( $file_paths ) )
  112. $file_paths = implode( "\n", $file_paths );
  113. echo '<p class="form-field"><label for="_file_paths">' . __( 'File paths (one per line)', 'woocommerce' ) . ':</label>
  114. <textarea style="float:left;height:5em;" id="_file_paths" class="short file_paths" cols="20" rows="3" placeholder="' . __( 'File paths/URLs, one per line', 'woocommerce' ) . '" name="_file_paths" wrap="off">' . esc_textarea( $file_paths ) . '</textarea>
  115. <input type="button" class="upload_file_button button" data-choose="' . __( 'Choose a file', 'woocommerce' ) . '" data-update="' . __( 'Insert file URL', 'woocommerce' ) . '" value="' . __( 'Choose a file', 'woocommerce' ) . '" />
  116. </p>';
  117. // Download Limit
  118. 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(
  119. 'step' => '1',
  120. 'min' => '0'
  121. ) ) );
  122. // Expirey
  123. 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(
  124. 'step' => '1',
  125. 'min' => '0'
  126. ) ) );
  127. do_action( 'woocommerce_product_options_downloads' );
  128. echo '</div>';
  129. if ( get_option( 'woocommerce_calc_taxes' ) == 'yes' ) {
  130. echo '<div class="options_group show_if_simple show_if_external show_if_variable">';
  131. // Tax
  132. woocommerce_wp_select( array( 'id' => '_tax_status', 'label' => __( 'Tax Status', 'woocommerce' ), 'options' => array(
  133. 'taxable' => __( 'Taxable', 'woocommerce' ),
  134. 'shipping' => __( 'Shipping only', 'woocommerce' ),
  135. 'none' => __( 'None', 'woocommerce' )
  136. ) ) );
  137. $tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'woocommerce_tax_classes' ) ) ) );
  138. $classes_options = array();
  139. $classes_options[''] = __( 'Standard', 'woocommerce' );
  140. if ( $tax_classes )
  141. foreach ( $tax_classes as $class )
  142. $classes_options[ sanitize_title( $class ) ] = esc_html( $class );
  143. woocommerce_wp_select( array( 'id' => '_tax_class', 'label' => __( 'Tax Class', 'woocommerce' ), 'options' => $classes_options ) );
  144. do_action( 'woocommerce_product_options_tax' );
  145. echo '</div>';
  146. }
  147. do_action( 'woocommerce_product_options_general_product_data' );
  148. ?>
  149. </div>
  150. <div id="inventory_product_data" class="panel woocommerce_options_panel">
  151. <?php
  152. echo '<div class="options_group">';
  153. if (get_option('woocommerce_manage_stock')=='yes') {
  154. // manage stock
  155. 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' ) ) );
  156. do_action('woocommerce_product_options_stock');
  157. echo '<div class="stock_fields show_if_simple show_if_variable">';
  158. // Stock
  159. woocommerce_wp_text_input( array( 'id' => '_stock', 'label' => __( 'Stock Qty', '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(
  160. 'step' => 'any'
  161. ) ) );
  162. do_action('woocommerce_product_options_stock_fields');
  163. echo '</div>';
  164. }
  165. // Stock status
  166. woocommerce_wp_select( array( 'id' => '_stock_status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
  167. 'instock' => __( 'In stock', 'woocommerce' ),
  168. 'outofstock' => __( 'Out of stock', 'woocommerce' )
  169. ), 'desc_tip' => true, 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ) ) );
  170. if (get_option('woocommerce_manage_stock')=='yes') {
  171. echo '<div class="show_if_simple show_if_variable">';
  172. // Backorders?
  173. woocommerce_wp_select( array( 'id' => '_backorders', 'label' => __( 'Allow Backorders?', 'woocommerce' ), 'options' => array(
  174. 'no' => __( 'Do not allow', 'woocommerce' ),
  175. 'notify' => __( 'Allow, but notify customer', 'woocommerce' ),
  176. 'yes' => __( 'Allow', 'woocommerce' )
  177. ), 'desc_tip' => true, 'description' => __( 'If managing stock, this controls whether or not backorders are allowed for this product and variations. If enabled, stock quantity can go below 0.', 'woocommerce' ) ) );
  178. echo '</div>';
  179. }
  180. echo '</div>';
  181. echo '<div class="options_group show_if_simple show_if_variable">';
  182. // Individual product
  183. 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') ) );
  184. do_action('woocommerce_product_options_sold_individually');
  185. echo '</div>';
  186. ?>
  187. </div>
  188. <div id="shipping_product_data" class="panel woocommerce_options_panel">
  189. <?php
  190. echo '<div class="options_group">';
  191. // Weight
  192. if( get_option('woocommerce_enable_weight', true) !== 'no' ) :
  193. woocommerce_wp_text_input( array( 'id' => '_weight', 'label' => __( 'Weight', 'woocommerce' ) . ' ('.get_option('woocommerce_weight_unit').')', 'placeholder' => '0.00', 'description' => __( 'Weight in decimal form', 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array(
  194. 'step' => 'any',
  195. 'min' => '0'
  196. ) ) );
  197. else:
  198. echo '<input type="hidden" name="_weight" value="' . esc_attr( get_post_meta( $thepostid, '_weight', true ) ) . '" />';
  199. endif;
  200. // Size fields
  201. if( get_option( 'woocommerce_enable_dimensions', true ) !== 'no' ) :
  202. ?><p class="form-field dimensions_field">
  203. <label for="product_length"><?php echo __( 'Dimensions', 'woocommerce' ) . ' (' . get_option( 'woocommerce_dimension_unit' ) . ')'; ?></label>
  204. <span class="wrap">
  205. <input id="product_length" placeholder="<?php _e( 'Length', 'woocommerce' ); ?>" class="input-text" size="6" type="number" name="_length" value="<?php echo esc_attr( get_post_meta( $thepostid, '_length', true ) ); ?>" step="any" min="0" />
  206. <input placeholder="<?php _e( 'Width', 'woocommerce' ); ?>" class="input-text" size="6" type="number" name="_width" value="<?php echo esc_attr( get_post_meta( $thepostid, '_width', true ) ); ?>" step="any" min="0" />
  207. <input placeholder="<?php _e( 'Height', 'woocommerce' ); ?>" class="input-text last" size="6" type="number" name="_height" value="<?php echo esc_attr( get_post_meta( $thepostid, '_height', true ) ); ?>" step="any" min="0" />
  208. </span>
  209. <span class="description"><?php _e( 'LxWxH in decimal form', 'woocommerce' ); ?></span>
  210. </p><?php
  211. else:
  212. echo '<input type="hidden" name="_length" value="' . esc_attr( get_post_meta( $thepostid, '_length', true ) ) . '" />';
  213. echo '<input type="hidden" name="_width" value="' . esc_attr( get_post_meta( $thepostid, '_width', true ) ) . '" />';
  214. echo '<input type="hidden" name="_height" value="' . esc_attr( get_post_meta( $thepostid, '_height', true ) ) . '" />';
  215. endif;
  216. do_action( 'woocommerce_product_options_dimensions' );
  217. echo '</div>';
  218. echo '<div class="options_group">';
  219. // Shipping Class
  220. $classes = get_the_terms( $thepostid, 'product_shipping_class' );
  221. if ( $classes && ! is_wp_error( $classes ) ) $current_shipping_class = current($classes)->term_id; else $current_shipping_class = '';
  222. $args = array(
  223. 'taxonomy' => 'product_shipping_class',
  224. 'hide_empty' => 0,
  225. 'show_option_none' => __( 'No shipping class', 'woocommerce' ),
  226. 'name' => 'product_shipping_class',
  227. 'id' => 'product_shipping_class',
  228. 'selected' => $current_shipping_class,
  229. 'class' => 'select short'
  230. );
  231. ?><p class="form-field dimensions_field"><label for="product_shipping_class"><?php _e( 'Shipping class', 'woocommerce' ); ?></label> <?php wp_dropdown_categories( $args ); ?> <span class="description"><?php _e( 'Shipping classes are used by certain shipping methods to group similar products.', 'woocommerce' ); ?></span></p><?php
  232. do_action( 'woocommerce_product_options_shipping' );
  233. echo '</div>';
  234. ?>
  235. </div>
  236. <div id="woocommerce_attributes" class="panel wc-metaboxes-wrapper">
  237. <p class="toolbar">
  238. <a href="#" class="close_all"><?php _e( 'Close all', 'woocommerce' ); ?></a><a href="#" class="expand_all"><?php _e( 'Expand all', 'woocommerce' ); ?></a>
  239. </p>
  240. <div class="woocommerce_attributes wc-metaboxes">
  241. <?php
  242. // Array of defined attribute taxonomies
  243. $attribute_taxonomies = $woocommerce->get_attribute_taxonomies();
  244. // Product attributes - taxonomies and custom, ordered, with visibility and variation attributes set
  245. $attributes = maybe_unserialize( get_post_meta( $thepostid, '_product_attributes', true ) );
  246. $i = -1;
  247. // Taxonomies
  248. if ( $attribute_taxonomies ) {
  249. foreach ( $attribute_taxonomies as $tax ) { $i++;
  250. // Get name of taxonomy we're now outputting (pa_xxx)
  251. $attribute_taxonomy_name = $woocommerce->attribute_taxonomy_name( $tax->attribute_name );
  252. // Ensure it exists
  253. if ( ! taxonomy_exists( $attribute_taxonomy_name ) ) continue;
  254. // Get product data values for current taxonomy - this contains ordering and visibility data
  255. if ( isset( $attributes[ $attribute_taxonomy_name ] ) )
  256. $attribute = $attributes[ $attribute_taxonomy_name ];
  257. $position = empty( $attribute['position'] ) ? 0 : absint( $attribute['position'] );
  258. // Get terms of this taxonomy associated with current product
  259. $post_terms = wp_get_post_terms( $thepostid, $attribute_taxonomy_name );
  260. // Any set?
  261. $has_terms = ( is_wp_error( $post_terms ) || ! $post_terms || sizeof( $post_terms ) == 0 ) ? 0 : 1;
  262. ?>
  263. <div class="woocommerce_attribute wc-metabox closed taxonomy <?php echo $attribute_taxonomy_name; ?>" rel="<?php echo $position; ?>" <?php if ( ! $has_terms ) echo 'style="display:none"'; ?>>
  264. <h3>
  265. <button type="button" class="remove_row button"><?php _e( 'Remove', 'woocommerce' ); ?></button>
  266. <div class="handlediv" title="<?php _e( 'Click to toggle', 'woocommerce' ); ?>"></div>
  267. <strong class="attribute_name"><?php echo apply_filters( 'woocommerce_attribute_label', $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name, $tax->attribute_name ); ?></strong>
  268. </h3>
  269. <table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data wc-metabox-content">
  270. <tbody>
  271. <tr>
  272. <td class="attribute_name">
  273. <label><?php _e( 'Name', 'woocommerce' ); ?>:</label>
  274. <strong><?php echo $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name; ?></strong>
  275. <input type="hidden" name="attribute_names[<?php echo $i; ?>]" value="<?php echo esc_attr( $attribute_taxonomy_name ); ?>" />
  276. <input type="hidden" name="attribute_position[<?php echo $i; ?>]" class="attribute_position" value="<?php echo esc_attr( $position ); ?>" />
  277. <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?>]" value="1" />
  278. </td>
  279. <td rowspan="3">
  280. <label><?php _e( 'Value(s)', 'woocommerce' ); ?>:</label>
  281. <?php if ( $tax->attribute_type == "select" ) : ?>
  282. <select multiple="multiple" data-placeholder="<?php _e( 'Select terms', 'woocommerce' ); ?>" class="multiselect attribute_values" name="attribute_values[<?php echo $i; ?>][]">
  283. <?php
  284. $all_terms = get_terms( $attribute_taxonomy_name, 'orderby=name&hide_empty=0' );
  285. if ( $all_terms ) {
  286. foreach ( $all_terms as $term ) {
  287. $has_term = has_term( $term->term_id, $attribute_taxonomy_name, $thepostid ) ? 1 : 0;
  288. echo '<option value="' . $term->slug . '" ' . selected( $has_term, 1, false ) . '>' . $term->name . '</option>';
  289. }
  290. }
  291. ?>
  292. </select>
  293. <button class="button plus select_all_attributes"><?php _e( 'Select all', 'woocommerce' ); ?></button> <button class="button minus select_no_attributes"><?php _e( 'Select none', 'woocommerce' ); ?></button>
  294. <button class="button fr plus add_new_attribute" data-attribute="<?php echo $attribute_taxonomy_name; ?>"><?php _e( 'Add new', 'woocommerce' ); ?></button>
  295. <?php elseif ( $tax->attribute_type == "text" ) : ?>
  296. <input type="text" name="attribute_values[<?php echo $i; ?>]" value="<?php
  297. // Text attributes should list terms pipe separated
  298. if ( $post_terms ) {
  299. $values = array();
  300. foreach ( $post_terms as $term )
  301. $values[] = $term->name;
  302. echo implode( ' | ', $values );
  303. }
  304. ?>" placeholder="<?php _e( 'Pipe (|) separate terms', 'woocommerce' ); ?>" />
  305. <?php endif; ?>
  306. <?php do_action( 'woocommerce_product_option_terms', $tax, $i ); ?>
  307. </td>
  308. </tr>
  309. <tr>
  310. <td>
  311. <label><input type="checkbox" class="checkbox" <?php
  312. if ( isset( $attribute['is_visible'] ) )
  313. checked( $attribute['is_visible'], 1 );
  314. else
  315. checked( apply_filters( 'default_attribute_visibility', false, $tax ), true );
  316. ?> name="attribute_visibility[<?php echo $i; ?>]" value="1" /> <?php _e( 'Visible on the product page', 'woocommerce' ); ?></label>
  317. </td>
  318. </tr>
  319. <tr>
  320. <td>
  321. <div class="enable_variation show_if_variable">
  322. <label><input type="checkbox" class="checkbox" <?php
  323. if ( isset( $attribute['is_variation'] ) )
  324. checked( $attribute['is_variation'], 1 );
  325. else
  326. checked( apply_filters( 'default_attribute_variation', false, $tax ), true );
  327. ?> name="attribute_variation[<?php echo $i; ?>]" value="1" /> <?php _e( 'Used for variations', 'woocommerce' ); ?></label>
  328. </div>
  329. </td>
  330. </tr>
  331. </tbody>
  332. </table>
  333. </div>
  334. <?php
  335. }
  336. }
  337. // Custom Attributes
  338. if ( ! empty( $attributes ) ) foreach ( $attributes as $attribute ) {
  339. if ( $attribute['is_taxonomy'] )
  340. continue;
  341. $i++;
  342. $position = empty( $attribute['position'] ) ? 0 : absint( $attribute['position'] );
  343. ?>
  344. <div class="woocommerce_attribute wc-metabox closed" rel="<?php echo $position; ?>">
  345. <h3>
  346. <button type="button" class="remove_row button"><?php _e( 'Remove', 'woocommerce' ); ?></button>
  347. <div class="handlediv" title="<?php _e( 'Click to toggle', 'woocommerce' ); ?>"></div>
  348. <strong class="attribute_name"><?php echo apply_filters( 'woocommerce_attribute_label', esc_html( $attribute['name'] ), esc_html( $attribute['name'] ) ); ?></strong>
  349. </h3>
  350. <table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data wc-metabox-content">
  351. <tbody>
  352. <tr>
  353. <td class="attribute_name">
  354. <label><?php _e( 'Name', 'woocommerce' ); ?>:</label>
  355. <input type="text" class="attribute_name" name="attribute_names[<?php echo $i; ?>]" value="<?php echo esc_attr( $attribute['name'] ); ?>" />
  356. <input type="hidden" name="attribute_position[<?php echo $i; ?>]" class="attribute_position" value="<?php echo esc_attr( $position ); ?>" />
  357. <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?>]" value="0" />
  358. </td>
  359. <td rowspan="3">
  360. <label><?php _e( 'Value(s)', 'woocommerce' ); ?>:</label>
  361. <textarea name="attribute_values[<?php echo $i; ?>]" cols="5" rows="5" placeholder="<?php _e( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce' ); ?>"><?php echo esc_textarea( $attribute['value'] ); ?></textarea>
  362. </td>
  363. </tr>
  364. <tr>
  365. <td>
  366. <label><input type="checkbox" class="checkbox" <?php checked( $attribute['is_visible'], 1 ); ?> name="attribute_visibility[<?php echo $i; ?>]" value="1" /> <?php _e( 'Visible on the product page', 'woocommerce' ); ?></label>
  367. </td>
  368. </tr>
  369. <tr>
  370. <td>
  371. <div class="enable_variation show_if_variable">
  372. <label><input type="checkbox" class="checkbox" <?php checked( $attribute['is_variation'], 1 ); ?> name="attribute_variation[<?php echo $i; ?>]" value="1" /> <?php _e( 'Used for variations', 'woocommerce' ); ?></label>
  373. </div>
  374. </td>
  375. </tr>
  376. </tbody>
  377. </table>
  378. </div>
  379. <?php
  380. }
  381. ?>
  382. </div>
  383. <p class="toolbar">
  384. <button type="button" class="button button-primary add_attribute"><?php _e( 'Add', 'woocommerce' ); ?></button>
  385. <select name="attribute_taxonomy" class="attribute_taxonomy">
  386. <option value=""><?php _e( 'Custom product attribute', 'woocommerce' ); ?></option>
  387. <?php
  388. if ( $attribute_taxonomies ) {
  389. foreach ( $attribute_taxonomies as $tax ) {
  390. $attribute_taxonomy_name = $woocommerce->attribute_taxonomy_name( $tax->attribute_name );
  391. $label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name;
  392. echo '<option value="' . esc_attr( $attribute_taxonomy_name ) . '">' . esc_html( $label ) . '</option>';
  393. }
  394. }
  395. ?>
  396. </select>
  397. <button type="button" class="button save_attributes"><?php _e( 'Save attributes', 'woocommerce' ); ?></button>
  398. </p>
  399. </div>
  400. <div id="linked_product_data" class="panel woocommerce_options_panel">
  401. <div class="options_group">
  402. <p class="form-field"><label for="upsell_ids"><?php _e( 'Up-Sells', 'woocommerce' ); ?></label>
  403. <select id="upsell_ids" name="upsell_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>">
  404. <?php
  405. $upsell_ids = get_post_meta( $post->ID, '_upsell_ids', true );
  406. $product_ids = ! empty( $upsell_ids ) ? array_map( 'absint', $upsell_ids ) : null;
  407. if ( $product_ids ) {
  408. foreach ( $product_ids as $product_id ) {
  409. $product = get_product( $product_id );
  410. $product_name = woocommerce_get_formatted_product_name( $product );
  411. echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
  412. }
  413. }
  414. ?>
  415. </select> <img class="help_tip" data-tip='<?php _e( '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' ) ?>' src="<?php echo $woocommerce->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /></p>
  416. <p class="form-field"><label for="crosssell_ids"><?php _e( 'Cross-Sells', 'woocommerce' ); ?></label>
  417. <select id="crosssell_ids" name="crosssell_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>">
  418. <?php
  419. $crosssell_ids = get_post_meta( $post->ID, '_crosssell_ids', true );
  420. $product_ids = ! empty( $crosssell_ids ) ? array_map( 'absint', $crosssell_ids ) : null;
  421. if ( $product_ids ) {
  422. foreach ( $product_ids as $product_id ) {
  423. $product = get_product( $product_id );
  424. $product_name = woocommerce_get_formatted_product_name( $product );
  425. echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
  426. }
  427. }
  428. ?>
  429. </select> <img class="help_tip" data-tip='<?php _e( 'Cross-sells are products which you promote in the cart, based on the current product.', 'woocommerce' ) ?>' src="<?php echo $woocommerce->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /></p>
  430. </div>
  431. <?php
  432. echo '<div class="options_group grouping show_if_simple show_if_external">';
  433. // List Grouped products
  434. $post_parents = array();
  435. $post_parents[''] = __( 'Choose a grouped product&hellip;', 'woocommerce' );
  436. $posts_in = array_unique( (array) get_objects_in_term( get_term_by( 'slug', 'grouped', 'product_type' )->term_id, 'product_type' ) );
  437. if ( sizeof( $posts_in ) > 0 ) {
  438. $args = array(
  439. 'post_type' => 'product',
  440. 'post_status' => 'any',
  441. 'numberposts' => -1,
  442. 'orderby' => 'title',
  443. 'order' => 'asc',
  444. 'post_parent' => 0,
  445. 'include' => $posts_in,
  446. );
  447. $grouped_products = get_posts( $args );
  448. if ( $grouped_products ) {
  449. foreach ( $grouped_products as $product ) {
  450. if ( $product->ID == $post->ID )
  451. continue;
  452. $post_parents[ $product->ID ] = $product->post_title;
  453. }
  454. }
  455. }
  456. woocommerce_wp_select( array( 'id' => 'parent_id', 'label' => __( 'Grouping', 'woocommerce' ), 'value' => absint( $post->post_parent ), 'options' => $post_parents, 'desc_tip' => true, 'description' => __( 'Set this option to make this product part of a grouped product.', 'woocommerce' ) ) );
  457. woocommerce_wp_hidden_input( array( 'id' => 'previous_parent_id', 'value' => absint( $post->post_parent ) ) );
  458. do_action( 'woocommerce_product_options_grouping' );
  459. echo '</div>';
  460. ?>
  461. <?php do_action( 'woocommerce_product_options_related' ); ?>
  462. </div>
  463. <div id="advanced_product_data" class="panel woocommerce_options_panel">
  464. <?php
  465. echo '<div class="options_group hide_if_external">';
  466. // Purchase note
  467. woocommerce_wp_textarea_input( array( 'id' => '_purchase_note', 'label' => __( 'Purchase Note', 'woocommerce' ), 'description' => __( 'Enter an optional note to send the customer after purchase.', 'woocommerce' ) ) );
  468. echo '</div>';
  469. echo '<div class="options_group">';
  470. // menu_order
  471. woocommerce_wp_text_input( array( 'id' => 'menu_order', 'label' => __( 'Menu order', 'woocommerce' ), 'description' => __( 'Custom ordering position.', 'woocommerce' ), 'value' => intval( $post->menu_order ), 'type' => 'number', 'custom_attributes' => array(
  472. 'step' => '1'
  473. ) ) );
  474. echo '</div>';
  475. echo '<div class="options_group reviews">';
  476. woocommerce_wp_checkbox( array( 'id' => 'comment_status', 'label' => __( 'Enable reviews', 'woocommerce' ), 'cbvalue' => 'open', 'value' => esc_attr( $post->comment_status ) ) );
  477. do_action( 'woocommerce_product_options_reviews' );
  478. echo '</div>';
  479. ?>
  480. </div>
  481. <?php do_action( 'woocommerce_product_write_panels' ); ?>
  482. <div class="clear"></div>
  483. </div>
  484. <?php
  485. }
  486. /**
  487. * Save the product data meta box.
  488. *
  489. * @access public
  490. * @param mixed $post_id
  491. * @param mixed $post
  492. * @return void
  493. */
  494. function woocommerce_process_product_meta( $post_id, $post ) {
  495. global $wpdb, $woocommerce, $woocommerce_errors;
  496. // Add any default post meta
  497. add_post_meta( $post_id, 'total_sales', '0', true );
  498. // Get types
  499. $product_type = empty( $_POST['product-type'] ) ? 'simple' : sanitize_title( stripslashes( $_POST['product-type'] ) );
  500. $is_downloadable = isset( $_POST['_downloadable'] ) ? 'yes' : 'no';
  501. $is_virtual = isset( $_POST['_virtual'] ) ? 'yes' : 'no';
  502. // Product type + Downloadable/Virtual
  503. wp_set_object_terms( $post_id, $product_type, 'product_type' );
  504. update_post_meta( $post_id, '_downloadable', $is_downloadable );
  505. update_post_meta( $post_id, '_virtual', $is_virtual );
  506. // Gallery Images
  507. $attachment_ids = array_filter( explode( ',', woocommerce_clean( $_POST['product_image_gallery'] ) ) );
  508. update_post_meta( $post_id, '_product_image_gallery', implode( ',', $attachment_ids ) );
  509. // Update post meta
  510. update_post_meta( $post_id, '_regular_price', stripslashes( $_POST['_regular_price'] ) );
  511. update_post_meta( $post_id, '_sale_price', stripslashes( $_POST['_sale_price'] ) );
  512. update_post_meta( $post_id, '_tax_status', stripslashes( $_POST['_tax_status'] ) );
  513. update_post_meta( $post_id, '_tax_class', stripslashes( $_POST['_tax_class'] ) );
  514. update_post_meta( $post_id, '_visibility', stripslashes( $_POST['_visibility'] ) );
  515. update_post_meta( $post_id, '_purchase_note', stripslashes( $_POST['_purchase_note'] ) );
  516. update_post_meta( $post_id, '_featured', isset( $_POST['_featured'] ) ? 'yes' : 'no' );
  517. // Dimensions
  518. if ( $is_virtual == 'no' ) {
  519. update_post_meta( $post_id, '_weight', stripslashes( $_POST['_weight'] ) );
  520. update_post_meta( $post_id, '_length', stripslashes( $_POST['_length'] ) );
  521. update_post_meta( $post_id, '_width', stripslashes( $_POST['_width'] ) );
  522. update_post_meta( $post_id, '_height', stripslashes( $_POST['_height'] ) );
  523. } else {
  524. update_post_meta( $post_id, '_weight', '' );
  525. update_post_meta( $post_id, '_length', '' );
  526. update_post_meta( $post_id, '_width', '' );
  527. update_post_meta( $post_id, '_height', '' );
  528. }
  529. // Save shipping class
  530. $product_shipping_class = $_POST['product_shipping_class'] > 0 && $product_type != 'external' ? absint( $_POST['product_shipping_class'] ) : '';
  531. wp_set_object_terms( $post_id, $product_shipping_class, 'product_shipping_class');
  532. // Unique SKU
  533. $sku = get_post_meta($post_id, '_sku', true);
  534. $new_sku = esc_html( trim( stripslashes( $_POST['_sku'] ) ) );
  535. if ( $new_sku == '' ) {
  536. update_post_meta( $post_id, '_sku', '' );
  537. } elseif ( $new_sku !== $sku ) {
  538. if ( ! empty( $new_sku ) ) {
  539. if (
  540. $wpdb->get_var( $wpdb->prepare("
  541. SELECT $wpdb->posts.ID
  542. FROM $wpdb->posts
  543. LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
  544. WHERE $wpdb->posts.post_type = 'product'
  545. AND $wpdb->posts.post_status = 'publish'
  546. AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
  547. ", $new_sku ) )
  548. ) {
  549. $woocommerce_errors[] = __( 'Product SKU must be unique.', 'woocommerce' );
  550. } else {
  551. update_post_meta( $post_id, '_sku', $new_sku );
  552. }
  553. } else {
  554. update_post_meta( $post_id, '_sku', '' );
  555. }
  556. }
  557. // Save Attributes
  558. $attributes = array();
  559. if ( isset( $_POST['attribute_names'] ) ) {
  560. $attribute_names = $_POST['attribute_names'];
  561. $attribute_values = $_POST['attribute_values'];
  562. if ( isset( $_POST['attribute_visibility'] ) )
  563. $attribute_visibility = $_POST['attribute_visibility'];
  564. if ( isset( $_POST['attribute_variation'] ) )
  565. $attribute_variation = $_POST['attribute_variation'];
  566. $attribute_is_taxonomy = $_POST['attribute_is_taxonomy'];
  567. $attribute_position = $_POST['attribute_position'];
  568. $attribute_names_count = sizeof( $attribute_names );
  569. for ( $i=0; $i < $attribute_names_count; $i++ ) {
  570. if ( ! $attribute_names[ $i ] )
  571. continue;
  572. $is_visible = isset( $attribute_visibility[ $i ] ) ? 1 : 0;
  573. $is_variation = isset( $attribute_variation[ $i ] ) ? 1 : 0;
  574. $is_taxonomy = $attribute_is_taxonomy[ $i ] ? 1 : 0;
  575. if ( $is_taxonomy ) {
  576. if ( isset( $attribute_values[ $i ] ) ) {
  577. // Format values
  578. if ( is_array( $attribute_values[ $i ] ) ) {
  579. $values = array_map( 'woocommerce_clean', $attribute_values[ $i ] );
  580. } else {
  581. // Text based, separate by pipe
  582. $values = array_map( 'woocommerce_clean', explode( '|', $attribute_values[ $i ] ) );
  583. }
  584. // Remove empty items in the array
  585. $values = array_filter( $values );
  586. } else {
  587. $values = array();
  588. }
  589. // Update post terms
  590. if ( taxonomy_exists( $attribute_names[ $i ] ) )
  591. wp_set_object_terms( $post_id, $values, $attribute_names[ $i ] );
  592. if ( $values ) {
  593. // Add attribute to array, but don't set values
  594. $attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
  595. 'name' => woocommerce_clean( $attribute_names[ $i ] ),
  596. 'value' => '',
  597. 'position' => $attribute_position[ $i ],
  598. 'is_visible' => $is_visible,
  599. 'is_variation' => $is_variation,
  600. 'is_taxonomy' => $is_taxonomy
  601. );
  602. }
  603. } elseif ( isset( $attribute_values[ $i ] ) ) {
  604. // Text based, separate by pipe
  605. $values = implode( ' | ', array_map( 'woocommerce_clean', explode( '|', $attribute_values[ $i ] ) ) );
  606. // Custom attribute - Add attribute to array and set the values
  607. $attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
  608. 'name' => woocommerce_clean( $attribute_names[ $i ] ),
  609. 'value' => $values,
  610. 'position' => $attribute_position[ $i ],
  611. 'is_visible' => $is_visible,
  612. 'is_variation' => $is_variation,
  613. 'is_taxonomy' => $is_taxonomy
  614. );
  615. }
  616. }
  617. }
  618. if ( ! function_exists( 'attributes_cmp' ) ) {
  619. function attributes_cmp( $a, $b ) {
  620. if ( $a['position'] == $b['position'] ) return 0;
  621. return ( $a['position'] < $b['position'] ) ? -1 : 1;
  622. }
  623. }
  624. uasort( $attributes, 'attributes_cmp' );
  625. update_post_meta( $post_id, '_product_attributes', $attributes );
  626. // Sales and prices
  627. if ( in_array( $product_type, array( 'variable', 'grouped' ) ) ) {
  628. // Variable and grouped products have no prices
  629. update_post_meta( $post_id, '_regular_price', '' );
  630. update_post_meta( $post_id, '_sale_price', '' );
  631. update_post_meta( $post_id, '_sale_price_dates_from', '' );
  632. update_post_meta( $post_id, '_sale_price_dates_to', '' );
  633. update_post_meta( $post_id, '_price', '' );
  634. } else {
  635. $date_from = isset( $_POST['_sale_price_dates_from'] ) ? $_POST['_sale_price_dates_from'] : '';
  636. $date_to = isset( $_POST['_sale_price_dates_to'] ) ? $_POST['_sale_price_dates_to'] : '';
  637. // Dates
  638. if ( $date_from )
  639. update_post_meta( $post_id, '_sale_price_dates_from', strtotime( $date_from ) );
  640. else
  641. update_post_meta( $post_id, '_sale_price_dates_from', '' );
  642. if ( $date_to )
  643. update_post_meta( $post_id, '_sale_price_dates_to', strtotime( $date_to ) );
  644. else
  645. update_post_meta( $post_id, '_sale_price_dates_to', '' );
  646. if ( $date_to && ! $date_from )
  647. update_post_meta( $post_id, '_sale_price_dates_from', strtotime( 'NOW', current_time( 'timestamp' ) ) );
  648. // Update price if on sale
  649. if ( $_POST['_sale_price'] != '' && $date_to == '' && $date_from == '' )
  650. update_post_meta( $post_id, '_price', stripslashes( $_POST['_sale_price'] ) );
  651. else
  652. update_post_meta( $post_id, '_price', stripslashes( $_POST['_regular_price'] ) );
  653. if ( $_POST['_sale_price'] != '' && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) )
  654. update_post_meta( $post_id, '_price', stripslashes($_POST['_sale_price']) );
  655. if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
  656. update_post_meta( $post_id, '_price', stripslashes($_POST['_regular_price']) );
  657. update_post_meta( $post_id, '_sale_price_dates_from', '');
  658. update_post_meta( $post_id, '_sale_price_dates_to', '');
  659. }
  660. }
  661. // Update parent if grouped so price sorting works and stays in sync with the cheapest child
  662. if ( $post->post_parent > 0 || $product_type == 'grouped' || $_POST['previous_parent_id'] > 0 ) {
  663. $clear_parent_ids = array();
  664. if ( $post->post_parent > 0 )
  665. $clear_parent_ids[] = $post->post_parent;
  666. if ( $product_type == 'grouped' )
  667. $clear_parent_ids[] = $post_id;
  668. if ( $_POST['previous_parent_id'] > 0 )
  669. $clear_parent_ids[] = absint( $_POST['previous_parent_id'] );
  670. if ( $clear_parent_ids ) {
  671. foreach( $clear_parent_ids as $clear_id ) {
  672. $children_by_price = get_posts( array(
  673. 'post_parent' => $clear_id,
  674. 'orderby' => 'meta_value_num',
  675. 'order' => 'asc',
  676. 'meta_key' => '_price',
  677. 'posts_per_page'=> 1,
  678. 'post_type' => 'product',
  679. 'fields' => 'ids'
  680. ) );
  681. if ( $children_by_price ) {
  682. foreach ( $children_by_price as $child ) {
  683. $child_price = get_post_meta( $child, '_price', true );
  684. update_post_meta( $clear_id, '_price', $child_price );
  685. }
  686. }
  687. // Clear cache/transients
  688. $woocommerce->clear_product_transients( $clear_id );
  689. }
  690. }
  691. }
  692. // Sold Individuall
  693. if ( ! empty( $_POST['_sold_individually'] ) ) {
  694. update_post_meta( $post_id, '_sold_individually', 'yes' );
  695. } else {
  696. update_post_meta( $post_id, '_sold_individually', '' );
  697. }
  698. // Stock Data
  699. if ( get_option('woocommerce_manage_stock') == 'yes' ) {
  700. if ( $product_type == 'grouped' ) {
  701. update_post_meta( $post_id, '_stock_status', stripslashes( $_POST['_stock_status'] ) );
  702. update_post_meta( $post_id, '_stock', '' );
  703. update_post_meta( $post_id, '_manage_stock', 'no' );
  704. update_post_meta( $post_id, '_backorders', 'no' );
  705. } elseif ( $product_type == 'external' ) {
  706. update_post_meta( $post_id, '_stock_status', 'instock' );
  707. update_post_meta( $post_id, '_stock', '' );
  708. update_post_meta( $post_id, '_manage_stock', 'no' );
  709. update_post_meta( $post_id, '_backorders', 'no' );
  710. } elseif ( ! empty( $_POST['_manage_stock'] ) ) {
  711. // Manage stock
  712. update_post_meta( $post_id, '_stock', (int) $_POST['_stock'] );
  713. update_post_meta( $post_id, '_stock_status', stripslashes( $_POST['_stock_status'] ) );
  714. update_post_meta( $post_id, '_backorders', stripslashes( $_POST['_backorders'] ) );
  715. update_post_meta( $post_id, '_manage_stock', 'yes' );
  716. // Check stock level
  717. if ( $product_type !== 'variable' && $_POST['_backorders'] == 'no' && (int) $_POST['_stock'] < 1 )
  718. update_post_meta( $post_id, '_stock_status', 'outofstock' );
  719. } else {
  720. // Don't manage stock
  721. update_post_meta( $post_id, '_stock', '' );
  722. update_post_meta( $post_id, '_stock_status', stripslashes( $_POST['_stock_status'] ) );
  723. update_post_meta( $post_id, '_backorders', stripslashes( $_POST['_backorders'] ) );
  724. update_post_meta( $post_id, '_manage_stock', 'no' );
  725. }
  726. } else {
  727. update_post_meta( $post_id, '_stock_status', stripslashes( $_POST['_stock_status'] ) );
  728. }
  729. // Upsells
  730. if ( isset( $_POST['upsell_ids'] ) ) {
  731. $upsells = array();
  732. $ids = $_POST['upsell_ids'];
  733. foreach ( $ids as $id )
  734. if ( $id && $id > 0 )
  735. $upsells[] = $id;
  736. update_post_meta( $post_id, '_upsell_ids', $upsells );
  737. } else {
  738. delete_post_meta( $post_id, '_upsell_ids' );
  739. }
  740. // Cross sells
  741. if ( isset( $_POST['crosssell_ids'] ) ) {
  742. $crosssells = array();
  743. $ids = $_POST['crosssell_ids'];
  744. foreach ( $ids as $id )
  745. if ( $id && $id > 0 )
  746. $crosssells[] = $id;
  747. update_post_meta( $post_id, '_crosssell_ids', $crosssells );
  748. } else {
  749. delete_post_meta( $post_id, '_crosssell_ids' );
  750. }
  751. // Downloadable options
  752. if ( $is_downloadable == 'yes' ) {
  753. $_download_limit = absint( $_POST['_download_limit'] );
  754. if ( ! $_download_limit )
  755. $_download_limit = ''; // 0 or blank = unlimited
  756. $_download_expiry = absint( $_POST['_download_expiry'] );
  757. if ( ! $_download_expiry )
  758. $_download_expiry = ''; // 0 or blank = unlimited
  759. // file paths will be stored in an array keyed off md5(file path)
  760. if ( isset( $_POST['_file_paths'] ) ) {
  761. $_file_paths = array();
  762. $file_paths = str_replace( "\r\n", "\n", esc_attr( $_POST['_file_paths'] ) );
  763. $file_paths = trim( preg_replace( "/\n+/", "\n", $file_paths ) );
  764. if ( $file_paths ) {
  765. $file_paths = explode( "\n", $file_paths );
  766. foreach ( $file_paths as $file_path ) {
  767. $file_path = trim( $file_path );
  768. $_file_paths[ md5( $file_path ) ] = $file_path;
  769. }
  770. }
  771. // grant permission to any newly added files on any existing orders for this product
  772. do_action( 'woocommerce_process_product_file_download_paths', $post_id, 0, $_file_paths );
  773. update_post_meta( $post_id, '_file_paths', $_file_paths );
  774. }
  775. if ( isset( $_POST['_download_limit'] ) )
  776. update_post_meta( $post_id, '_download_limit', esc_attr( $_download_limit ) );
  777. if ( isset( $_POST['_download_expiry'] ) )
  778. update_post_meta( $post_id, '_download_expiry', esc_attr( $_download_expiry ) );
  779. }
  780. // Product url
  781. if ( $product_type == 'external' ) {
  782. if ( isset( $_POST['_product_url'] ) && $_POST['_product_url'] )
  783. update_post_meta( $post_id, '_product_url', esc_attr( $_POST['_product_url'] ) );
  784. if ( isset( $_POST['_button_text'] ) && $_POST['_button_text'] )
  785. update_post_meta( $post_id, '_button_text', esc_attr( $_POST['_button_text'] ) );
  786. }
  787. // Do action for product type
  788. do_action( 'woocommerce_process_product_meta_' . $product_type, $post_id );
  789. // Clear cache/transients
  790. $woocommerce->clear_product_transients( $post_id );
  791. }
  792. add_action('woocommerce_process_product_meta', 'woocommerce_process_product_meta', 1, 2);
  793. /**
  794. * Output product visibility options.
  795. *
  796. * @access public
  797. * @return void
  798. */
  799. function woocommerce_product_data_visibility() {
  800. global $post;
  801. if ( $post->post_type != 'product' )
  802. return;
  803. $current_visibility = ( $current_visibility = get_post_meta( $post->ID, '_visibility', true ) ) ? $current_visibility : 'visible';
  804. $current_featured = ( $current_featured = get_post_meta( $post->ID, '_featured', true ) ) ? $current_featured : 'no';
  805. $visibility_options = apply_filters( 'woocommerce_product_visibility_options', array(
  806. 'visible' => __( 'Catalog/search', 'woocommerce' ),
  807. 'catalog' => __( 'Catalog', 'woocommerce' ),
  808. 'search' => __( 'Search', 'woocommerce' ),
  809. 'hidden' => __( 'Hidden', 'woocommerce' )
  810. ) );
  811. ?>
  812. <div class="misc-pub-section" id="catalog-visibility">
  813. <?php _e( 'Catalog visibility:', 'woocommerce' ); ?> <strong id="catalog-visibility-display"><?php
  814. echo isset( $visibility_options[ $current_visibility ] ) ? esc_html( $visibility_options[ $current_visibility ] ) : esc_html( $current_visibility );
  815. if ( $current_featured == 'yes' )
  816. echo ', ' . __( 'Featured', 'woocommerce' );
  817. ?></strong>
  818. <a href="#catalog-visibility" class="edit-catalog-visibility hide-if-no-js"><?php _e( 'Edit', 'woocommerce' ); ?></a>
  819. <div id="catalog-visibility-select" class="hide-if-js">
  820. <input type="hidden" name="current_visibility" id="current_visibility" value="<?php echo esc_attr( $current_visibility ); ?>" />
  821. <input type="hidden" name="current_featured" id="current_featured" value="<?php echo esc_attr( $current_featured ); ?>" />
  822. <?php
  823. echo '<p>' . __( 'Define the loops this product should be visible in. The product will still be accessible directly.', 'woocommerce' ) . '</p>';
  824. foreach ( $visibility_options as $name => $label ) {
  825. echo '<input type="radio" name="_visibility" id="_visibility_' . esc_attr( $name ) . '" value="' . esc_attr( $name ) . '" ' . checked( $current_visibility, $name, false ) . ' data-label="' . esc_attr( $label ) . '" /> <label for="_visibility_' . esc_attr( $name ) . '" class="selectit">' . esc_html( $label ) . '</label><br />';
  826. }
  827. echo '<p>' . __( 'Enable this option to feature this product.', 'woocommerce' ) . '</p>';
  828. echo '<input type="checkbox" name="_featured" id="_featured" ' . checked( $current_featured, 'yes', false ) . ' /> <label for="_featured">' . __( 'Featured Product', 'woocommerce' ) . '</label><br />';
  829. ?>
  830. <p>
  831. <a href="#catalog-visibility" class="save-post-visibility hide-if-no-js button"><?php _e( 'OK', 'woocommerce' ); ?></a>
  832. <a href="#catalog-visibility" class="cancel-post-visibility hide-if-no-js"><?php _e( 'Cancel', 'woocommerce' ); ?></a>
  833. </p>
  834. </div>
  835. </div>
  836. <?php
  837. }
  838. add_action( 'post_submitbox_misc_actions', 'woocommerce_product_data_visibility' );