PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

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

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