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

/admin/post-types/writepanels/writepanel-product_data.php

https://github.com/alexcsandru/woocommerce
PHP | 1072 lines | 730 code | 245 blank | 97 comment | 131 complexity | 885634790cf83531016c87ce2ccf6d7a MD5 | raw file
Possible License(s): GPL-3.0
  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 = current( $terms )->slug;
  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. $attribute_taxonomies = $woocommerce->get_attribute_taxonomies(); // Array of defined attribute taxonomies
  243. $attributes = maybe_unserialize( get_post_meta( $thepostid, '_product_attributes', true ) ); // Product attributes - taxonomies and custom, ordered, with visibility and variation attributes set
  244. $i = -1;
  245. // Taxonomies
  246. if ( $attribute_taxonomies ) {
  247. foreach ( $attribute_taxonomies as $tax ) { $i++;
  248. // Get name of taxonomy we're now outputting (pa_xxx)
  249. $attribute_taxonomy_name = $woocommerce->attribute_taxonomy_name( $tax->attribute_name );
  250. // Ensure it exists
  251. if ( ! taxonomy_exists( $attribute_taxonomy_name ) ) continue;
  252. // Get product data values for current taxonomy - this contains ordering and visibility data
  253. if ( isset( $attributes[ $attribute_taxonomy_name ] ) )
  254. $attribute = $attributes[ $attribute_taxonomy_name ];
  255. $position = empty( $attribute['position'] ) ? 0 : absint( $attribute['position'] );
  256. // Get terms of this taxonomy associated with current product
  257. $post_terms = wp_get_post_terms( $thepostid, $attribute_taxonomy_name );
  258. // Any set?
  259. $has_terms = ( is_wp_error( $post_terms ) || ! $post_terms || sizeof( $post_terms ) == 0 ) ? 0 : 1;
  260. ?>
  261. <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"'; ?>>
  262. <h3>
  263. <button type="button" class="remove_row button"><?php _e( 'Remove', 'woocommerce' ); ?></button>
  264. <div class="handlediv" title="<?php _e( 'Click to toggle', 'woocommerce' ); ?>"></div>
  265. <strong class="attribute_name"><?php echo apply_filters( 'woocommerce_attribute_label', $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name, $tax->attribute_name ); ?></strong>
  266. </h3>
  267. <table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data wc-metabox-content">
  268. <tbody>
  269. <tr>
  270. <td class="attribute_name">
  271. <label><?php _e( 'Name', 'woocommerce' ); ?>:</label>
  272. <strong><?php echo $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name; ?></strong>
  273. <input type="hidden" name="attribute_names[<?php echo $i; ?>]" value="<?php echo esc_attr( $attribute_taxonomy_name ); ?>" />
  274. <input type="hidden" name="attribute_position[<?php echo $i; ?>]" class="attribute_position" value="<?php echo esc_attr( $position ); ?>" />
  275. <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?>]" value="1" />
  276. </td>
  277. <td rowspan="3">
  278. <label><?php _e( 'Value(s)', 'woocommerce' ); ?>:</label>
  279. <?php if ( $tax->attribute_type == "select" ) : ?>
  280. <select multiple="multiple" data-placeholder="<?php _e( 'Select terms', 'woocommerce' ); ?>" class="multiselect attribute_values" name="attribute_values[<?php echo $i; ?>][]">
  281. <?php
  282. $all_terms = get_terms( $attribute_taxonomy_name, 'orderby=name&hide_empty=0' );
  283. if ( $all_terms ) {
  284. foreach ( $all_terms as $term ) {
  285. $has_term = has_term( $term->term_id, $attribute_taxonomy_name, $thepostid ) ? 1 : 0;
  286. echo '<option value="' . $term->slug . '" ' . selected( $has_term, 1, false ) . '>' . $term->name . '</option>';
  287. }
  288. }
  289. ?>
  290. </select>
  291. <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>
  292. <button class="button fr plus add_new_attribute" data-attribute="<?php echo $attribute_taxonomy_name; ?>"><?php _e( 'Add new', 'woocommerce' ); ?></button>
  293. <?php elseif ( $tax->attribute_type == "text" ) : ?>
  294. <input type="text" name="attribute_values[<?php echo $i; ?>]" value="<?php
  295. // Text attributes should list terms pipe separated
  296. if ( $post_terms ) {
  297. $values = array();
  298. foreach ( $post_terms as $term )
  299. $values[] = $term->name;
  300. echo implode( '|', $values );
  301. }
  302. ?>" placeholder="<?php _e( 'Pipe separate terms', 'woocommerce' ); ?>" />
  303. <?php endif; ?>
  304. <?php do_action( 'woocommerce_product_option_terms', $tax, $i ); ?>
  305. </td>
  306. </tr>
  307. <tr>
  308. <td>
  309. <label><input type="checkbox" class="checkbox" <?php if ( ! empty( $attribute['is_visible'] ) ) checked( $attribute['is_visible'], 1 ); ?> name="attribute_visibility[<?php echo $i; ?>]" value="1" /> <?php _e( 'Visible on the product page', 'woocommerce' ); ?></label>
  310. </td>
  311. </tr>
  312. <tr>
  313. <td>
  314. <div class="enable_variation show_if_variable">
  315. <label><input type="checkbox" class="checkbox" <?php if ( ! empty( $attribute['is_variation'] ) ) checked( $attribute['is_variation'], 1 ); ?> name="attribute_variation[<?php echo $i; ?>]" value="1" /> <?php _e( 'Used for variations', 'woocommerce' ); ?></label>
  316. </div>
  317. </td>
  318. </tr>
  319. </tbody>
  320. </table>
  321. </div>
  322. <?php
  323. }
  324. }
  325. // Custom Attributes
  326. if ( ! empty( $attributes ) ) foreach ( $attributes as $attribute ) {
  327. if ( $attribute['is_taxonomy'] ) continue;
  328. $i++;
  329. $position = empty( $attribute['position'] ) ? 0 : absint( $attribute['position'] );
  330. ?>
  331. <div class="woocommerce_attribute wc-metabox closed" rel="<?php echo $position; ?>">
  332. <h3>
  333. <button type="button" class="remove_row button"><?php _e( 'Remove', 'woocommerce' ); ?></button>
  334. <div class="handlediv" title="<?php _e( 'Click to toggle', 'woocommerce' ); ?>"></div>
  335. <strong class="attribute_name"><?php echo apply_filters( 'woocommerce_attribute_label', esc_html( $attribute['name'] ), esc_html( $attribute['name'] ) ); ?></strong>
  336. </h3>
  337. <table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data wc-metabox-content">
  338. <tbody>
  339. <tr>
  340. <td class="attribute_name">
  341. <label><?php _e( 'Name', 'woocommerce' ); ?>:</label>
  342. <input type="text" class="attribute_name" name="attribute_names[<?php echo $i; ?>]" value="<?php echo esc_attr( $attribute['name'] ); ?>" />
  343. <input type="hidden" name="attribute_position[<?php echo $i; ?>]" class="attribute_position" value="<?php echo esc_attr( $position ); ?>" />
  344. <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?>]" value="0" />
  345. </td>
  346. <td rowspan="3">
  347. <label><?php _e( 'Value(s)', 'woocommerce' ); ?>:</label>
  348. <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>
  349. </td>
  350. </tr>
  351. <tr>
  352. <td>
  353. <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>
  354. </td>
  355. </tr>
  356. <tr>
  357. <td>
  358. <div class="enable_variation show_if_variable">
  359. <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>
  360. </div>
  361. </td>
  362. </tr>
  363. </tbody>
  364. </table>
  365. </div>
  366. <?php
  367. }
  368. ?>
  369. </div>
  370. <p class="toolbar">
  371. <button type="button" class="button button-primary add_attribute"><?php _e( 'Add', 'woocommerce' ); ?></button>
  372. <select name="attribute_taxonomy" class="attribute_taxonomy">
  373. <option value=""><?php _e( 'Custom product attribute', 'woocommerce' ); ?></option>
  374. <?php
  375. if ( $attribute_taxonomies ) {
  376. foreach ( $attribute_taxonomies as $tax ) {
  377. $attribute_taxonomy_name = $woocommerce->attribute_taxonomy_name( $tax->attribute_name );
  378. $label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name;
  379. echo '<option value="' . esc_attr( $attribute_taxonomy_name ) . '">' . esc_html( $label ) . '</option>';
  380. }
  381. }
  382. ?>
  383. </select>
  384. <button type="button" class="button save_attributes"><?php _e( 'Save attributes', 'woocommerce' ); ?></button>
  385. </p>
  386. </div>
  387. <div id="linked_product_data" class="panel woocommerce_options_panel">
  388. <div class="options_group">
  389. <p class="form-field"><label for="upsell_ids"><?php _e( 'Up-Sells', 'woocommerce' ); ?></label>
  390. <select id="upsell_ids" name="upsell_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>">
  391. <?php
  392. $upsell_ids = get_post_meta( $post->ID, '_upsell_ids', true );
  393. $product_ids = ! empty( $upsell_ids ) ? array_map( 'absint', $upsell_ids ) : null;
  394. if ( $product_ids ) {
  395. foreach ( $product_ids as $product_id ) {
  396. $product = get_product( $product_id );
  397. $product_name = woocommerce_get_formatted_product_name( $product );
  398. echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
  399. }
  400. }
  401. ?>
  402. </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>
  403. <p class="form-field"><label for="crosssell_ids"><?php _e( 'Cross-Sells', 'woocommerce' ); ?></label>
  404. <select id="crosssell_ids" name="crosssell_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product&hellip;', 'woocommerce' ); ?>">
  405. <?php
  406. $crosssell_ids = get_post_meta( $post->ID, '_crosssell_ids', true );
  407. $product_ids = ! empty( $crosssell_ids ) ? array_map( 'absint', $crosssell_ids ) : null;
  408. if ( $product_ids ) {
  409. foreach ( $product_ids as $product_id ) {
  410. $product = get_product( $product_id );
  411. $product_name = woocommerce_get_formatted_product_name( $product );
  412. echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
  413. }
  414. }
  415. ?>
  416. </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>
  417. </div>
  418. <?php
  419. echo '<div class="options_group grouping show_if_simple show_if_external">';
  420. // List Grouped products
  421. $post_parents = array();
  422. $post_parents[''] = __( 'Choose a grouped product&hellip;', 'woocommerce' );
  423. $posts_in = array_unique( (array) get_objects_in_term( get_term_by( 'slug', 'grouped', 'product_type' )->term_id, 'product_type' ) );
  424. if ( sizeof( $posts_in ) > 0 ) {
  425. $args = array(
  426. 'post_type' => 'product',
  427. 'post_status' => 'any',
  428. 'numberposts' => -1,
  429. 'orderby' => 'title',
  430. 'order' => 'asc',
  431. 'post_parent' => 0,
  432. 'include' => $posts_in,
  433. );
  434. $grouped_products = get_posts( $args );
  435. if ( $grouped_products ) {
  436. foreach ( $grouped_products as $product ) {
  437. if ( $product->ID == $post->ID )
  438. continue;
  439. $post_parents[ $product->ID ] = $product->post_title;
  440. }
  441. }
  442. }
  443. 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' ) ) );
  444. woocommerce_wp_hidden_input( array( 'id' => 'previous_parent_id', 'value' => absint( $post->post_parent ) ) );
  445. do_action( 'woocommerce_product_options_grouping' );
  446. echo '</div>';
  447. ?>
  448. <?php do_action( 'woocommerce_product_options_related' ); ?>
  449. </div>
  450. <div id="advanced_product_data" class="panel woocommerce_options_panel">
  451. <?php
  452. echo '<div class="options_group hide_if_external">';
  453. // Purchase note
  454. woocommerce_wp_textarea_input( array( 'id' => '_purchase_note', 'label' => __( 'Purchase Note', 'woocommerce' ), 'description' => __( 'Enter an optional note to send the customer after purchase.', 'woocommerce' ) ) );
  455. echo '</div>';
  456. echo '<div class="options_group">';
  457. // menu_order
  458. 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(
  459. 'step' => '1'
  460. ) ) );
  461. echo '</div>';
  462. echo '<div class="options_group reviews">';
  463. woocommerce_wp_checkbox( array( 'id' => 'comment_status', 'label' => __( 'Enable reviews', 'woocommerce' ), 'cbvalue' => 'open', 'value' => esc_attr( $post->comment_status ) ) );
  464. do_action( 'woocommerce_product_options_reviews' );
  465. echo '</div>';
  466. ?>
  467. </div>
  468. <?php do_action( 'woocommerce_product_write_panels' ); ?>
  469. <div class="clear"></div>
  470. </div>
  471. <?php
  472. }
  473. /**
  474. * Save the product data meta box.
  475. *
  476. * @access public
  477. * @param mixed $post_id
  478. * @param mixed $post
  479. * @return void
  480. */
  481. function woocommerce_process_product_meta( $post_id, $post ) {
  482. global $wpdb, $woocommerce, $woocommerce_errors;
  483. // Add any default post meta
  484. add_post_meta( $post_id, 'total_sales', '0', true );
  485. // Get types
  486. $product_type = empty( $_POST['product-type'] ) ? 'simple' : sanitize_title( stripslashes( $_POST['product-type'] ) );
  487. $is_downloadable = isset( $_POST['_downloadable'] ) ? 'yes' : 'no';
  488. $is_virtual = isset( $_POST['_virtual'] ) ? 'yes' : 'no';
  489. // Product type + Downloadable/Virtual
  490. wp_set_object_terms( $post_id, $product_type, 'product_type' );
  491. update_post_meta( $post_id, '_downloadable', $is_downloadable );
  492. update_post_meta( $post_id, '_virtual', $is_virtual );
  493. // Gallery Images
  494. $attachment_ids = array_filter( explode( ',', woocommerce_clean( $_POST['product_image_gallery'] ) ) );
  495. update_post_meta( $post_id, '_product_image_gallery', implode( ',', $attachment_ids ) );
  496. // Update post meta
  497. update_post_meta( $post_id, '_regular_price', stripslashes( $_POST['_regular_price'] ) );
  498. update_post_meta( $post_id, '_sale_price', stripslashes( $_POST['_sale_price'] ) );
  499. update_post_meta( $post_id, '_tax_status', stripslashes( $_POST['_tax_status'] ) );
  500. update_post_meta( $post_id, '_tax_class', stripslashes( $_POST['_tax_class'] ) );
  501. update_post_meta( $post_id, '_visibility', stripslashes( $_POST['_visibility'] ) );
  502. update_post_meta( $post_id, '_purchase_note', stripslashes( $_POST['_purchase_note'] ) );
  503. update_post_meta( $post_id, '_featured', isset( $_POST['_featured'] ) ? 'yes' : 'no' );
  504. // Dimensions
  505. if ( $is_virtual == 'no' ) {
  506. update_post_meta( $post_id, '_weight', stripslashes( $_POST['_weight'] ) );
  507. update_post_meta( $post_id, '_length', stripslashes( $_POST['_length'] ) );
  508. update_post_meta( $post_id, '_width', stripslashes( $_POST['_width'] ) );
  509. update_post_meta( $post_id, '_height', stripslashes( $_POST['_height'] ) );
  510. } else {
  511. update_post_meta( $post_id, '_weight', '' );
  512. update_post_meta( $post_id, '_length', '' );
  513. update_post_meta( $post_id, '_width', '' );
  514. update_post_meta( $post_id, '_height', '' );
  515. }
  516. // Save shipping class
  517. $product_shipping_class = $_POST['product_shipping_class'] > 0 && $product_type != 'external' ? absint( $_POST['product_shipping_class'] ) : '';
  518. wp_set_object_terms( $post_id, $product_shipping_class, 'product_shipping_class');
  519. // Unique SKU
  520. $sku = get_post_meta($post_id, '_sku', true);
  521. $new_sku = esc_html( trim( stripslashes( $_POST['_sku'] ) ) );
  522. if ( $new_sku == '' ) {
  523. update_post_meta( $post_id, '_sku', '' );
  524. } elseif ( $new_sku !== $sku ) {
  525. if ( ! empty( $new_sku ) ) {
  526. if (
  527. $wpdb->get_var( $wpdb->prepare("
  528. SELECT $wpdb->posts.ID
  529. FROM $wpdb->posts
  530. LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
  531. WHERE $wpdb->posts.post_type = 'product'
  532. AND $wpdb->posts.post_status = 'publish'
  533. AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
  534. ", $new_sku ) )
  535. ) {
  536. $woocommerce_errors[] = __( 'Product SKU must be unique.', 'woocommerce' );
  537. } else {
  538. update_post_meta( $post_id, '_sku', $new_sku );
  539. }
  540. } else {
  541. update_post_meta( $post_id, '_sku', '' );
  542. }
  543. }
  544. // Save Attributes
  545. $attributes = array();
  546. if ( isset( $_POST['attribute_names'] ) ) {
  547. $attribute_names = $_POST['attribute_names'];
  548. $attribute_values = $_POST['attribute_values'];
  549. if ( isset( $_POST['attribute_visibility'] ) )
  550. $attribute_visibility = $_POST['attribute_visibility'];
  551. if ( isset( $_POST['attribute_variation'] ) )
  552. $attribute_variation = $_POST['attribute_variation'];
  553. $attribute_is_taxonomy = $_POST['attribute_is_taxonomy'];
  554. $attribute_position = $_POST['attribute_position'];
  555. $attribute_names_count = sizeof( $attribute_names );
  556. for ( $i=0; $i < $attribute_names_count; $i++ ) {
  557. if ( ! $attribute_names[ $i ] )
  558. continue;
  559. $is_visible = isset( $attribute_visibility[ $i ] ) ? 1 : 0;
  560. $is_variation = isset( $attribute_variation[ $i ] ) ? 1 : 0;
  561. $is_taxonomy = $attribute_is_taxonomy[ $i ] ? 1 : 0;
  562. if ( $is_taxonomy ) {
  563. if ( isset( $attribute_values[ $i ] ) ) {
  564. // Format values
  565. if ( is_array( $attribute_values[ $i ] ) ) {
  566. $values = array_map('htmlspecialchars', array_map('stripslashes', $attribute_values[ $i ]));
  567. } else {
  568. // Text based, separate by pipe
  569. $values = htmlspecialchars( stripslashes( $attribute_values[ $i ] ) );
  570. $values = explode( '|', $values );
  571. $values = array_map( 'trim', $values );
  572. }
  573. // Remove empty items in the array
  574. $values = array_filter( $values );
  575. } else {
  576. $values = array();
  577. }
  578. // Update post terms
  579. if ( taxonomy_exists( $attribute_names[ $i ] ) )
  580. wp_set_object_terms( $post_id, $values, $attribute_names[ $i ] );
  581. if ( $values ) {
  582. // Add attribute to array, but don't set values
  583. $attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
  584. 'name' => htmlspecialchars( stripslashes( $attribute_names[ $i ] ) ),
  585. 'value' => '',
  586. 'position' => $attribute_position[ $i ],
  587. 'is_visible' => $is_visible,
  588. 'is_variation' => $is_variation,
  589. 'is_taxonomy' => $is_taxonomy
  590. );
  591. }
  592. } elseif ( isset( $attribute_values[ $i ] ) ) {
  593. // Text based, separate by pipe
  594. $values = implode( '|', array_map( 'esc_html', array_map( 'trim', explode( '|', stripslashes( $attribute_values[ $i ] ) ) ) ) );
  595. // Custom attribute - Add attribute to array and set the values
  596. $attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
  597. 'name' => htmlspecialchars( stripslashes( $attribute_names[ $i ] ) ),
  598. 'value' => $values,
  599. 'position' => $attribute_position[ $i ],
  600. 'is_visible' => $is_visible,
  601. 'is_variation' => $is_variation,
  602. 'is_taxonomy' => $is_taxonomy
  603. );
  604. }
  605. }
  606. }
  607. if ( ! function_exists( 'attributes_cmp' ) ) {
  608. function attributes_cmp( $a, $b ) {
  609. if ( $a['position'] == $b['position'] ) return 0;
  610. return ( $a['position'] < $b['position'] ) ? -1 : 1;
  611. }
  612. }
  613. uasort( $attributes, 'attributes_cmp' );
  614. update_post_meta( $post_id, '_product_attributes', $attributes );
  615. // Sales and prices
  616. if ( in_array( $product_type, array( 'variable', 'grouped' ) ) ) {
  617. // Variable and grouped products have no prices
  618. update_post_meta( $post_id, '_regular_price', '' );
  619. update_post_meta( $post_id, '_sale_price', '' );
  620. update_post_meta( $post_id, '_sale_price_dates_from', '' );
  621. update_post_meta( $post_id, '_sale_price_dates_to', '' );
  622. update_post_meta( $post_id, '_price', '' );
  623. } else {
  624. $date_from = isset( $_POST['_sale_price_dates_from'] ) ? $_POST['_sale_price_dates_from'] : '';
  625. $date_to = isset( $_POST['_sale_price_dates_to'] ) ? $_POST['_sale_price_dates_to'] : '';
  626. // Dates
  627. if ( $date_from )
  628. update_post_meta( $post_id, '_sale_price_dates_from', strtotime( $date_from ) );
  629. else
  630. update_post_meta( $post_id, '_sale_price_dates_from', '' );
  631. if ( $date_to )
  632. update_post_meta( $post_id, '_sale_price_dates_to', strtotime( $date_to ) );
  633. else
  634. update_post_meta( $post_id, '_sale_price_dates_to', '' );
  635. if ( $date_to && ! $date_from )
  636. update_post_meta( $post_id, '_sale_price_dates_from', strtotime( 'NOW', current_time( 'timestamp' ) ) );
  637. // Update price if on sale
  638. if ( $_POST['_sale_price'] != '' && $date_to == '' && $date_from == '' )
  639. update_post_meta( $post_id, '_price', stripslashes( $_POST['_sale_price'] ) );
  640. else
  641. update_post_meta( $post_id, '_price', stripslashes( $_POST['_regular_price'] ) );
  642. if ( $_POST['_sale_price'] != '' && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) )
  643. update_post_meta( $post_id, '_price', stripslashes($_POST['_sale_price']) );
  644. if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
  645. update_post_meta( $post_id, '_price', stripslashes($_POST['_regular_price']) );
  646. update_post_meta( $post_id, '_sale_price_dates_from', '');
  647. update_post_meta( $post_id, '_sale_price_dates_to', '');
  648. }
  649. }
  650. // Update parent if grouped so price sorting works and stays in sync with the cheapest child
  651. if ( $post->post_parent > 0 || $product_type == 'grouped' || $_POST['previous_parent_id'] > 0 ) {
  652. $clear_parent_ids = array();
  653. if ( $post->post_parent > 0 )
  654. $clear_parent_ids[] = $post->post_parent;
  655. if ( $product_type == 'grouped' )
  656. $clear_parent_ids[] = $post_id;
  657. if ( $_POST['previous_parent_id'] > 0 )
  658. $clear_parent_ids[] = absint( $_POST['previous_parent_id'] );
  659. if ( $clear_parent_ids ) {
  660. foreach( $clear_parent_ids as $clear_id ) {
  661. $children_by_price = get_posts( array(
  662. 'post_parent' => $clear_id,
  663. 'orderby' => 'meta_value_num',
  664. 'order' => 'asc',
  665. 'meta_key' => '_price',
  666. 'posts_per_page'=> 1,
  667. 'post_type' => 'product',
  668. 'fields' => 'ids'
  669. ) );
  670. if ( $children_by_price ) {
  671. foreach ( $children_by_price as $child ) {
  672. $child_price = get_post_meta( $child, '_price', true );
  673. update_post_meta( $clear_id, '_price', $child_price );
  674. }
  675. }
  676. // Clear cache/transients
  677. $woocommerce->clear_product_transients( $clear_id );
  678. }
  679. }
  680. }
  681. // Sold Individuall
  682. if ( ! empty( $_POST['_sold_individually'] ) ) {
  683. update_post_meta( $post_id, '_sold_individually', 'yes' );
  684. } else {
  685. update_post_meta( $post_id, '_sold_individually', '' );
  686. }
  687. // Stock Data
  688. if ( get_option('woocommerce_manage_stock') == 'yes' ) {
  689. if ( $product_type == 'grouped' ) {
  690. update_post_meta( $post_id, '_stock_status', stripslashes( $_POST['_stock_status'] ) );
  691. update_post_meta( $post_id, '_stock', '' );
  692. update_post_meta( $post_id, '_manage_stock', 'no' );
  693. update_post_meta( $post_id, '_backorders', 'no' );
  694. } elseif ( $product_type == 'external' ) {
  695. update_post_meta( $post_id, '_stock_status', 'instock' );
  696. update_post_meta( $post_id, '_stock', '' );
  697. update_post_meta( $post_id, '_manage_stock', 'no' );
  698. update_post_meta( $post_id, '_backorders', 'no' );
  699. } elseif ( ! empty( $_POST['_manage_stock'] ) ) {
  700. // Manage stock
  701. update_post_meta( $post_id, '_stock', (int) $_POST['_stock'] );
  702. update_post_meta( $post_id, '_stock_status', stripslashes( $_POST['_stock_status'] ) );
  703. update_post_meta( $post_id, '_backorders', stripslashes( $_POST['_backorders'] ) );
  704. update_post_meta( $post_id, '_manage_stock', 'yes' );
  705. // Check stock level
  706. if ( $product_type !== 'variable' && $_POST['_backorders'] == 'no' && (int) $_POST['_stock'] < 1 )
  707. update_post_meta( $post_id, '_stock_status', 'outofstock' );
  708. } else {
  709. // Don't manage stock
  710. update_post_meta( $post_id, '_stock', '' );
  711. update_post_meta( $post_id, '_stock_status', stripslashes( $_POST['_stock_status'] ) );
  712. update_post_meta( $post_id, '_backorders', stripslashes( $_POST['_backorders'] ) );
  713. update_post_meta( $post_id, '_manage_stock', 'no' );
  714. }
  715. } else {
  716. update_post_meta( $post_id, '_stock_status', stripslashes( $_POST['_stock_status'] ) );
  717. }
  718. // Upsells
  719. if ( isset( $_POST['upsell_ids'] ) ) {
  720. $upsells = array();
  721. $ids = $_POST['upsell_ids'];
  722. foreach ( $ids as $id )
  723. if ( $id && $id > 0 )
  724. $upsells[] = $id;
  725. update_post_meta( $post_id, '_upsell_ids', $upsells );
  726. } else {
  727. delete_post_meta( $post_id, '_upsell_ids' );
  728. }
  729. // Cross sells
  730. if ( isset( $_POST['crosssell_ids'] ) ) {
  731. $crosssells = array();
  732. $ids = $_POST['crosssell_ids'];
  733. foreach ( $ids as $id )
  734. if ( $id && $id > 0 )
  735. $crosssells[] = $id;
  736. update_post_meta( $post_id, '_crosssell_ids', $crosssells );
  737. } else {
  738. delete_post_meta( $post_id, '_crosssell_ids' );
  739. }
  740. // Downloadable options
  741. if ( $is_downloadable == 'yes' ) {
  742. $_download_limit = absint( $_POST['_download_limit'] );
  743. if ( ! $_download_limit )
  744. $_download_limit = ''; // 0 or blank = unlimited
  745. $_download_expiry = absint( $_POST['_download_expiry'] );
  746. if ( ! $_download_expiry )
  747. $_download_expiry = ''; // 0 or blank = unlimited
  748. // file paths will be stored in an array keyed off md5(file path)
  749. if ( isset( $_POST['_file_paths'] ) ) {
  750. $_file_paths = array();
  751. $file_paths = str_replace( "\r\n", "\n", esc_attr( $_POST['_file_paths'] ) );
  752. $file_paths = trim( preg_replace( "/\n+/", "\n", $file_paths ) );
  753. if ( $file_paths ) {
  754. $file_paths = explode( "\n", $file_paths );
  755. foreach ( $file_paths as $file_path ) {
  756. $file_path = trim( $file_path );
  757. $_file_paths[ md5( $file_path ) ] = $file_path;
  758. }
  759. }
  760. // grant permission to any newly added files on any existing orders for this product
  761. do_action( 'woocommerce_process_product_file_download_paths', $post_id, 0, $_file_paths );
  762. update_post_meta( $post_id, '_file_paths', $_file_paths );
  763. }
  764. if ( isset( $_POST['_download_limit'] ) )
  765. update_post_meta( $post_id, '_download_limit', esc_attr( $_download_limit ) );
  766. if ( isset( $_POST['_download_expiry'] ) )
  767. update_post_meta( $post_id, '_download_expiry', esc_attr( $_download_expiry ) );
  768. }
  769. // Product url
  770. if ( $product_type == 'external' ) {
  771. if ( isset( $_POST['_product_url'] ) && $_POST['_product_url'] )
  772. update_post_meta( $post_id, '_product_url', esc_attr( $_POST['_product_url'] ) );
  773. if ( isset( $_POST['_button_text'] ) && $_POST['_button_text'] )
  774. update_post_meta( $post_id, '_button_text', esc_attr( $_POST['_button_text'] ) );
  775. }
  776. // Do action for product type
  777. do_action( 'woocommerce_process_product_meta_' . $product_type, $post_id );
  778. // Clear cache/transients
  779. $woocommerce->clear_product_transients( $post_id );
  780. }
  781. add_action('woocommerce_process_product_meta', 'woocommerce_process_product_meta', 1, 2);
  782. /**
  783. * Output product visibility options.
  784. *
  785. * @access public
  786. * @return void
  787. */
  788. function woocommerce_product_data_visibility() {
  789. global $post;
  790. if ( $post->post_type != 'product' )
  791. return;
  792. $current_visibility = ( $current_visibility = get_post_meta( $post->ID, '_visibility', true ) ) ? $current_visibility : 'visible';
  793. $current_featured = ( $current_featured = get_post_meta( $post->ID, '_featured', true ) ) ? $current_featured : 'no';
  794. $visibility_options = apply_filters( 'woocommerce_product_visibility_options', array(
  795. 'visible' => __( 'Catalog/search', 'woocommerce' ),
  796. 'catalog' => __( 'Catalog', 'woocommerce' ),
  797. 'search' => __( 'Search', 'woocommerce' ),
  798. 'hidden' => __( 'Hidden', 'woocommerce' )
  799. ) );
  800. ?>
  801. <div class="misc-pub-section" id="catalog-visibility">
  802. <?php _e( 'Catalog visibility:', 'woocommerce' ); ?> <strong id="catalog-visibility-display"><?php
  803. echo isset( $visibility_options[ $current_visibility ] ) ? esc_html( $visibility_options[ $current_visibility ] ) : esc_html( $current_visibility );
  804. if ( $current_featured == 'yes' )
  805. echo ', ' . __( 'Featured', 'woocommerce' );
  806. ?></strong>
  807. <a href="#catalog-visibility" class="edit-catalog-visibility hide-if-no-js"><?php _e( 'Edit', 'woocommerce' ); ?></a>
  808. <div id="catalog-visibility-select" class="hide-if-js">
  809. <input type="hidden" name="current_visibility" id="current_visibility" value="<?php echo esc_attr( $current_visibility ); ?>" />
  810. <input type="hidden" name="current_featured" id="current_featured" value="<?php echo esc_attr( $current_featured ); ?>" />
  811. <?php
  812. echo '<p>' . __( 'Define the loops this product should be visible in. The product will still be accessible directly.', 'woocommerce' ) . '</p>';
  813. foreach ( $visibility_options as $name => $label ) {
  814. 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 />';
  815. }
  816. echo '<p>' . __( 'Enable this option to feature this product.', 'woocommerce' ) . '</p>';
  817. echo '<input type="checkbox" name="_featured" id="_featured" ' . checked( $current_featured, 'yes', false ) . ' /> <label for="_featured">' . __( 'Featured Product', 'woocommerce' ) . '</label><br />';
  818. ?>
  819. <p>
  820. <a href="#catalog-visibility" class="save-post-visibility hide-if-no-js button"><?php _e( 'OK', 'woocommerce' ); ?></a>
  821. <a href="#catalog-visibility" class="cancel-post-visibility hide-if-no-js"><?php _e( 'Cancel', 'woocommerce' ); ?></a>
  822. </p>
  823. </div>
  824. </div>
  825. <?php
  826. }
  827. add_action( 'post_submitbox_misc_actions', 'woocommerce_product_data_visibility' );