PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/write-panels/product-data.php

https://github.com/ThemesWpFr/jigoshop
PHP | 710 lines | 558 code | 91 blank | 61 comment | 41 complexity | 63bdd9a0aeaeef62b71f0eb98be8b313 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. * DISCLAIMER
  8. *
  9. * Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
  10. * versions in the future. If you wish to customise Jigoshop core for your needs,
  11. * please use our GitHub repository to publish essential changes for consideration.
  12. *
  13. * @package Jigoshop
  14. * @category Admin
  15. * @author Jigowatt
  16. * @copyright Copyright Š 2011-2012 Jigowatt Ltd.
  17. * @license http://jigoshop.com/license/commercial-edition
  18. */
  19. /**
  20. * Change label for insert buttons
  21. */
  22. add_filter( 'gettext', 'jigoshop_change_insert_into_post', null, 2 );
  23. function jigoshop_change_insert_into_post( $translation, $original ) {
  24. // Check if the translation is correct
  25. if( ! isset( $_REQUEST['from'] ) || $original != 'Insert into Post' )
  26. return $translation;
  27. // Modify text based on context
  28. switch ($_REQUEST['from']) {
  29. case 'jigoshop_variation':
  30. return __('Attach to Variation', 'jigoshop' );
  31. break;
  32. case 'jigoshop_product':
  33. return __('Attach to Product', 'jigoshop' );
  34. break;
  35. default:
  36. return $translation;
  37. }
  38. }
  39. /**
  40. * Product data box
  41. *
  42. * Displays the product data box, tabbed, with several panels covering price, stock etc
  43. *
  44. * @since 1.0
  45. */
  46. function jigoshop_product_data_box() {
  47. global $post, $wpdb, $thepostid;
  48. add_action('admin_footer', 'jigoshop_meta_scripts');
  49. wp_nonce_field( 'jigoshop_save_data', 'jigoshop_meta_nonce' );
  50. $thepostid = $post->ID;
  51. ?>
  52. <div class="panels">
  53. <ul class="product_data_tabs tabs" style="display:none;">
  54. <li class="general_tab active">
  55. <a href="#general"><?php _e('General', 'jigoshop'); ?></a>
  56. </li>
  57. <li class="advanced_tab">
  58. <a href="#tax"><?php _e('Advanced', 'jigoshop') ?></a>
  59. </li>
  60. <?php if (Jigoshop_Base::get_options()->get_option('jigoshop_manage_stock') == 'yes') : ?>
  61. <li class="inventory_tab">
  62. <a href="#inventory"><?php _e('Inventory', 'jigoshop'); ?></a>
  63. </li>
  64. <?php endif; ?>
  65. <li class="attributes_tab">
  66. <a href="#attributes"><?php _e('Attributes', 'jigoshop'); ?></a>
  67. </li>
  68. <li class="grouped_tab">
  69. <a href="#grouped"><?php _e('Grouping', 'jigoshop') ?></a>
  70. </li>
  71. <li class="file_tab">
  72. <a href="#files"><?php _e('File', 'jigoshop') ?></a>
  73. </li>
  74. <?php do_action('jigoshop_product_write_panel_tabs'); ?>
  75. <?php do_action('product_write_panel_tabs'); // Legacy ?>
  76. </ul>
  77. <div id="general" class="panel jigoshop_options_panel">
  78. <fieldset>
  79. <?php
  80. // Product Type
  81. $terms = get_the_terms( $thepostid, 'product_type' );
  82. $product_type = ($terms) ? current($terms)->slug : 'simple';
  83. $args = array(
  84. 'id' => 'product-type',
  85. 'label' => __('Product Type', 'jigoshop'),
  86. 'options' => apply_filters( 'jigoshop_product_type_selector', array(
  87. 'simple' => __('Simple', 'jigoshop'),
  88. 'downloadable' => __('Downloadable', 'jigoshop'),
  89. 'grouped' => __('Grouped', 'jigoshop'),
  90. 'virtual' => __('Virtual', 'jigoshop'),
  91. 'variable' => __('Variable', 'jigoshop'),
  92. 'external' => __('External / Affiliate', 'jigoshop')
  93. )),
  94. 'selected' => $product_type,
  95. );
  96. echo Jigoshop_Forms::select( $args );
  97. // SKU
  98. if ( Jigoshop_Base::get_options()->get_option('jigoshop_enable_sku') !== 'no' ) {
  99. $args = array(
  100. 'id' => 'sku',
  101. 'label' => __('SKU','jigoshop'),
  102. 'placeholder' => $post->ID,
  103. );
  104. echo Jigoshop_Forms::input( $args );
  105. }
  106. ?>
  107. </fieldset>
  108. <fieldset id="price_fieldset">
  109. <?php
  110. // Regular Price
  111. $args = array(
  112. 'id' => 'regular_price',
  113. 'label' => __('Regular Price','jigoshop'),
  114. 'after_label' => ' ('.get_jigoshop_currency_symbol().')',
  115. 'type' => 'number',
  116. 'step' => 'any',
  117. 'placeholder' => __('Price Not Announced','jigoshop'),
  118. );
  119. echo Jigoshop_Forms::input( $args );
  120. // Sale Price
  121. $args = array(
  122. 'id' => 'sale_price',
  123. 'label' => __('Sale Price','jigoshop'),
  124. 'after_label' => ' ('.get_jigoshop_currency_symbol(). __(' or %','jigoshop') . ')',
  125. 'desc' => '<a href="#" class="sale_schedule">'.__('Schedule','jigoshop').'</a>',
  126. 'placeholder' => __('15% or 19.99','jigoshop'),
  127. );
  128. echo Jigoshop_Forms::input( $args );
  129. // Sale Price date range
  130. // TODO: Convert this to a helper somehow?
  131. $field = array( 'id' => 'sale_price_dates', 'label' => __('On Sale Between', 'jigoshop') );
  132. $sale_price_dates_from = get_post_meta($thepostid, 'sale_price_dates_from', true);
  133. $sale_price_dates_to = get_post_meta($thepostid, 'sale_price_dates_to', true);
  134. echo ' <p class="form-field sale_price_dates_fields">
  135. <label for="' . esc_attr( $field['id'] ) . '_from">'.$field['label'].'</label>
  136. <input type="text" class="short date-pick" name="' . esc_attr( $field['id'] ) . '_from" id="' . esc_attr( $field['id'] ) . '_from" value="';
  137. if ($sale_price_dates_from) echo date('Y-m-d', $sale_price_dates_from);
  138. echo '" placeholder="' . __('From', 'jigoshop') . ' (' . date('Y-m-d'). ')" maxlength="10" />
  139. <input type="text" class="short date-pick" name="' . esc_attr( $field['id'] ) . '_to" id="' . esc_attr( $field['id'] ) . '_to" value="';
  140. if ($sale_price_dates_to) echo date('Y-m-d', $sale_price_dates_to);
  141. echo '" placeholder="' . __('To', 'jigoshop') . ' (' . date('Y-m-d'). ')" maxlength="10" />
  142. <a href="#" class="cancel_sale_schedule">'.__('Cancel', 'jigoshop').'</a>
  143. </p>';
  144. ?>
  145. <?php do_action( 'jigoshop_product_pricing_options' ); /* allow extensions like sales flash pro to add pricing options */ ?>
  146. </fieldset>
  147. <fieldset>
  148. <?php
  149. // Featured
  150. $args = array(
  151. 'id' => 'featured',
  152. 'label' => __('Featured?','jigoshop'),
  153. 'desc' => __('Enable this option to feature this product', 'jigoshop'),
  154. 'value' => false
  155. );
  156. echo Jigoshop_Forms::checkbox( $args );
  157. $args = array(
  158. 'id' => 'external_url',
  159. 'label' => __( 'Product URL', 'jigoshop' ),
  160. 'placeholder' => __( 'The URL of the external product (eg. http://www.google.com)', 'jigoshop' ),
  161. 'extras' => array()
  162. );
  163. echo Jigoshop_Forms::input( $args );
  164. ?>
  165. </fieldset>
  166. </div>
  167. <div id="tax" class="panel jigoshop_options_panel">
  168. <fieldset id="tax_fieldset">
  169. <?php
  170. // Tax Status
  171. $args = array(
  172. 'id' => 'tax_status',
  173. 'label' => __('Tax Status','jigoshop'),
  174. 'options' => array(
  175. 'taxable' => __('Taxable','jigoshop'),
  176. 'shipping' => __('Shipping','jigoshop'),
  177. 'none' => __('None','jigoshop')
  178. )
  179. );
  180. echo Jigoshop_Forms::select( $args );
  181. ?>
  182. <p class="form_field tax_classes_field">
  183. <label for="tax_classes"><?php _e('Tax Classes', 'jigoshop'); ?></label>
  184. <span class="multiselect short">
  185. <?php
  186. $_tax = new jigoshop_tax();
  187. $tax_classes = $_tax->get_tax_classes();
  188. $selections = (array) get_post_meta($post->ID, 'tax_classes', true);
  189. $checked = checked(in_array('*', $selections), true, false);
  190. printf('<label %s><input type="checkbox" name="tax_classes[]" value="%s" %s/> %s</label>'
  191. , !empty($checked) || $selections[0] == '' ? 'class="selected"' : ''
  192. , '*'
  193. , $checked
  194. , __('Standard', 'jigoshop'));
  195. if( $tax_classes ) {
  196. foreach ($tax_classes as $tax_class) {
  197. $checked = checked(in_array(sanitize_title($tax_class), $selections), true, false);
  198. printf('<label %s><input type="checkbox" name="tax_classes[]" value="%s" %s/> %s</label>'
  199. , !empty($checked) ? 'class="selected"' : ''
  200. , sanitize_title($tax_class)
  201. , $checked
  202. , __($tax_class, 'jigoshop'));
  203. }
  204. }
  205. ?>
  206. </span>
  207. <span class="multiselect-controls">
  208. <a class="check-all" href="#"><?php _e('Check All','jigoshop'); ?></a>&nbsp;|
  209. <a class="uncheck-all" href="#"><?php _e('Uncheck All','jigoshop');?></a>
  210. </span>
  211. </p>
  212. </fieldset>
  213. <?php if( Jigoshop_Base::get_options()->get_option('jigoshop_enable_weight') !== 'no' || Jigoshop_Base::get_options()->get_option('jigoshop_enable_dimensions', true) !== 'no' ): ?>
  214. <fieldset id="form_fieldset">
  215. <?php
  216. // Weight
  217. if( Jigoshop_Base::get_options()->get_option('jigoshop_enable_weight') !== 'no' ) {
  218. $args = array(
  219. 'id' => 'weight',
  220. 'label' => __( 'Weight', 'jigoshop' ),
  221. 'after_label' => ' ('.Jigoshop_Base::get_options()->get_option('jigoshop_weight_unit').')',
  222. 'type' => 'number',
  223. 'step' => 'any',
  224. 'placeholder' => '0.00',
  225. );
  226. echo Jigoshop_Forms::input( $args );
  227. }
  228. // Dimensions
  229. if( Jigoshop_Base::get_options()->get_option('jigoshop_enable_dimensions', true) !== 'no' ) {
  230. echo '
  231. <p class="form-field dimensions_field">
  232. <label for"product_length">'. __('Dimensions', 'jigoshop') . ' ('.Jigoshop_Base::get_options()->get_option('jigoshop_dimension_unit').')' . '</label>
  233. <input type="number" step="any" name="length" class="short" value="' . get_post_meta( $thepostid, 'length', true ) . '" placeholder="'. _e('Length', 'jigoshop') . '" />
  234. <input type="number" step="any" name="width" class="short" value="' . get_post_meta( $thepostid, 'width', true ) . '" placeholder="'. _e('Width', 'jigoshop') . '" />
  235. <input type="number" step="any" name="height" class="short" value="' . get_post_meta( $thepostid, 'height', true ) . '" placeholder="'. _e('Height', 'jigoshop') . '" />
  236. </p>
  237. ';
  238. }
  239. ?>
  240. </fieldset>
  241. <?php endif; ?>
  242. <fieldset>
  243. <?php
  244. // Visibility
  245. $args = array(
  246. 'id' => 'product_visibility',
  247. 'label' => __('Visibility','jigoshop'),
  248. 'options' => array(
  249. 'visible' => __('Catalog & Search','jigoshop'),
  250. 'catalog' => __('Catalog Only','jigoshop'),
  251. 'search' => __('Search Only','jigoshop'),
  252. 'hidden' => __('Hidden','jigoshop')
  253. ),
  254. 'selected' => get_post_meta( $post->ID, 'visibility', true )
  255. );
  256. echo Jigoshop_Forms::select( $args );
  257. ?>
  258. </fieldset>
  259. <fieldset>
  260. <?php
  261. // Customizable
  262. $args = array(
  263. 'id' => 'product_customize',
  264. 'label' => __('Can be personalized','jigoshop'),
  265. 'options' => array(
  266. 'no' => __('No','jigoshop'),
  267. 'yes' => __('Yes','jigoshop'),
  268. ),
  269. 'selected' => get_post_meta( $post->ID, 'customizable', true ),
  270. );
  271. echo Jigoshop_Forms::select( $args );
  272. // Customizable length
  273. $args = array(
  274. 'id' => 'customized_length',
  275. 'label' => __('Personalized Characters','jigoshop'),
  276. 'type' => 'number',
  277. 'value' => get_post_meta($post->ID, 'customized_length', true),
  278. 'placeholder' => __('Leave blank for unlimited', 'jigoshop'),
  279. );
  280. echo Jigoshop_Forms::input( $args );
  281. ?>
  282. </fieldset>
  283. </div>
  284. <?php if (Jigoshop_Base::get_options()->get_option('jigoshop_manage_stock')=='yes') : ?>
  285. <div id="inventory" class="panel jigoshop_options_panel">
  286. <fieldset>
  287. <?php
  288. // manage stock
  289. $args = array(
  290. 'id' => 'manage_stock',
  291. 'label' => __('Manage Stock?','jigoshop'),
  292. 'desc' => __('Handle stock for me', 'jigoshop'),
  293. 'value' => false
  294. );
  295. echo Jigoshop_Forms::checkbox( $args );
  296. ?>
  297. </fieldset>
  298. <fieldset>
  299. <?php
  300. // Stock Status
  301. // TODO: These values should be true/false
  302. $args = array(
  303. 'id' => 'stock_status',
  304. 'label' => __( 'Stock Status', 'jigoshop' ),
  305. 'options' => array(
  306. 'instock' => __('In Stock','jigoshop'),
  307. 'outofstock' => __('Out of Stock','jigoshop')
  308. )
  309. );
  310. echo Jigoshop_Forms::select( $args );
  311. echo '<div class="stock_fields">';
  312. // Stock
  313. // TODO: Missing default value of 0
  314. $args = array(
  315. 'id' => 'stock',
  316. 'label' => __('Stock Quantity','jigoshop'),
  317. 'type' => 'number',
  318. );
  319. echo Jigoshop_Forms::input( $args );
  320. // Backorders
  321. $args = array(
  322. 'id' => 'backorders',
  323. 'label' => __('Allow Backorders?','jigoshop'),
  324. 'options' => array(
  325. 'no' => __('Do not allow','jigoshop'),
  326. 'notify' => __('Allow, but notify customer','jigoshop'),
  327. 'yes' => __('Allow','jigoshop')
  328. )
  329. );
  330. echo Jigoshop_Forms::select( $args );
  331. echo '</div>';
  332. ?>
  333. </fieldset>
  334. </div>
  335. <?php endif; ?>
  336. <div id="attributes" class="panel">
  337. <?php do_action('jigoshop_attributes_display'); ?>
  338. </div>
  339. <div id="grouped" class="panel jigoshop_options_panel">
  340. <?php
  341. // Grouped Products
  342. // TODO: Needs refactoring & a bit of love
  343. $posts_in = (array) get_objects_in_term( get_term_by( 'slug', 'grouped', 'product_type' )->term_id, 'product_type' );
  344. $posts_in = array_unique($posts_in);
  345. if( (bool) $posts_in ) {
  346. $args = array(
  347. 'post_type' => 'product',
  348. 'post_status' => 'publish',
  349. 'numberposts' => -1,
  350. 'orderby' => 'title',
  351. 'order' => 'asc',
  352. 'post_parent' => 0,
  353. 'include' => $posts_in,
  354. );
  355. $grouped_products = get_posts($args);
  356. $options = array( null => '&ndash; Pick a Product Group &ndash;' );
  357. if( $grouped_products ) foreach( $grouped_products as $product ) {
  358. if ($product->ID==$post->ID) continue;
  359. $options[$product->ID] = $product->post_title;
  360. }
  361. // Only echo the form if we have grouped products
  362. $args = array(
  363. 'id' => 'parent_id',
  364. 'label' => __( 'Product Group', 'jigoshop' ),
  365. 'options' => $options,
  366. 'selected' => $post->post_parent,
  367. );
  368. echo Jigoshop_Forms::select( $args );
  369. }
  370. // Ordering
  371. $args = array(
  372. 'id' => 'menu_order',
  373. 'label' => __('Sort Order', 'jigoshop'),
  374. 'type' => 'number',
  375. 'value' => $post->menu_order,
  376. );
  377. echo Jigoshop_Forms::input( $args );
  378. ?>
  379. </div>
  380. <div id="files" class="panel jigoshop_options_panel">
  381. <fieldset>
  382. <?php
  383. // DOWNLOADABLE OPTIONS
  384. // File URL
  385. // TODO: Refactor this into a helper
  386. $file_path = get_post_meta($post->ID, 'file_path', true);
  387. $field = array( 'id' => 'file_path', 'label' => __('File Path', 'jigoshop') );
  388. echo '<p class="form-field"><label for="' . esc_attr( $field['id'] ) . '">'.$field['label'].':</label>
  389. <input type="text" class="file_path" name="'.esc_attr($field['id']).'" id="'.esc_attr($field['id']).'" value="'.esc_attr($file_path).'" placeholder="'.site_url().'" />
  390. <input type="button" class="upload_file_button button" data-postid="'.esc_attr($post->ID).'" value="'.__('Upload a file', 'jigoshop').'" />
  391. </p>';
  392. // Download Limit
  393. $args = array(
  394. 'id' => 'download_limit',
  395. 'label' => __( 'Download Limit', 'jigoshop' ),
  396. 'type' => 'number',
  397. 'desc' => __( 'Leave blank for unlimited re-downloads', 'jigoshop' ),
  398. );
  399. echo Jigoshop_Forms::input( $args );
  400. do_action( 'additional_downloadable_product_type_options' );
  401. ?>
  402. </fieldset>
  403. </div>
  404. <?php do_action('jigoshop_product_write_panels'); ?>
  405. <?php do_action('product_write_panels'); ?>
  406. </div>
  407. <?php
  408. }
  409. add_action('jigoshop_attributes_display', 'attributes_display');
  410. function attributes_display() { ?>
  411. <div class="toolbar">
  412. <button type="button" class="button button-secondary add_attribute"><?php _e('Add Attribute', 'jigoshop'); ?></button>
  413. <select name="attribute_taxonomy" class="attribute_taxonomy">
  414. <option value="" data-type="custom"><?php _e('Custom product attribute', 'jigoshop'); ?></option>
  415. <?php
  416. global $post;
  417. $attribute_taxonomies = jigoshop_product::getAttributeTaxonomies();
  418. if ( $attribute_taxonomies ) :
  419. foreach ($attribute_taxonomies as $tax) :
  420. $label = ($tax->attribute_label) ? $tax->attribute_label : $tax->attribute_name;
  421. $attributes = (array) get_post_meta($post->ID, 'product_attributes', true);
  422. $disabled = disabled( array_key_exists( sanitize_title( $label ), $attributes ), true, false );
  423. echo '<option value="'.esc_attr( sanitize_title($tax->attribute_name) ).'"'.$disabled.' data-type="'.esc_attr( $tax->attribute_type ).'">'.esc_attr( $label ).'</option>';
  424. endforeach;
  425. endif;
  426. ?>
  427. </select>
  428. </div>
  429. <div class="jigoshop_attributes_wrapper">
  430. <?php do_action('jigoshop_display_attribute'); ?>
  431. </div>
  432. <div class="clear"></div>
  433. <?php
  434. }
  435. add_action('jigoshop_display_attribute', 'display_attribute');
  436. function display_attribute() {
  437. global $post;
  438. // TODO: This needs refactoring
  439. // This is getting all the taxonomies
  440. $attribute_taxonomies = jigoshop_product::getAttributeTaxonomies();
  441. // Sneaky way of doing sort by desc
  442. $attribute_taxonomies = array_reverse($attribute_taxonomies);
  443. // This is whats applied to the product
  444. $attributes = get_post_meta($post->ID, 'product_attributes', true);
  445. ?>
  446. <!-- Disabling Demo attribute help display for 1.3 per support personnel request -JAP- -->
  447. <!--?php if( ! $attributes ): ?-->
  448. <!--div class="demo attribute">
  449. <a href="http://forum.jigoshop.com/kb" target="_blank" class="overlay"><span><?php _e('Learn how to set up Product Attributes', 'jigoshop'); ?></span></a>
  450. <div class="inside">
  451. <div class="postbox attribute">
  452. <button type="button" class="hide_row button">Remove</button>
  453. <div class="handlediv" title="Click to toggle"><br></div>
  454. <h3 class="handle">Size</h3>
  455. <div class="inside">
  456. <table>
  457. <tr>
  458. <td class="options">
  459. <input type="text" class="attribute-name" value="Size" disabled="disabled" />
  460. <div>
  461. <label>
  462. <input type="checkbox" value="1" checked="checked" />
  463. Display on product page
  464. </label>
  465. </div>
  466. </td>
  467. <td class="value">
  468. <select>
  469. <option>Choose an option&hellip;</option>
  470. </select>
  471. </td>
  472. </tr>
  473. </table>
  474. </div>
  475. </div>
  476. </div>
  477. </div-->
  478. <!--?php endif; ?-->
  479. <?php
  480. $i = -1;
  481. foreach ($attribute_taxonomies as $tax) :
  482. $i++;
  483. $attribute_taxonomy_name = sanitize_title($tax->attribute_name);
  484. if (isset($attributes[$attribute_taxonomy_name])) $attribute = $attributes[$attribute_taxonomy_name];
  485. $position = (isset($attribute['position'])) ? $attribute['position'] : 0;
  486. $allterms = wp_get_object_terms( $post->ID, 'pa_'.$attribute_taxonomy_name, array( 'orderby' => 'slug' ) );
  487. $has_terms = ( is_wp_error( $allterms ) || !$allterms || sizeof( $allterms ) == 0 ) ? 0 : 1;
  488. $term_slugs = array();
  489. if ( !is_wp_error( $allterms ) && $allterms ) :
  490. foreach ($allterms as $term) :
  491. $term_slugs[] = $term->slug;
  492. endforeach;
  493. endif;
  494. ?>
  495. <div class="postbox attribute <?php if ( $has_terms ) echo 'closed'; ?> <?php echo esc_attr( $attribute_taxonomy_name ); ?>" data-attribute-name="<?php echo esc_attr( $attribute_taxonomy_name ); ?>" rel="<?php echo $position; ?>" <?php if ( !$has_terms ) echo 'style="display:none"'; ?>>
  496. <button type="button" class="hide_row button"><?php _e('Remove', 'jigoshop'); ?></button>
  497. <div class="handlediv" title="<?php _e('Click to toggle', 'jigoshop') ?>"><br></div>
  498. <h3 class="handle">
  499. <?php $label = ($tax->attribute_label) ? $tax->attribute_label : $tax->attribute_name;
  500. echo esc_attr ( $label ); ?>
  501. </h3>
  502. <input type="hidden" name="attribute_names[<?php echo $i; ?>]" value="<?php echo esc_attr( sanitize_title ( $tax->attribute_name ) ); ?>" />
  503. <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?>]" value="1" />
  504. <input type="hidden" name="attribute_enabled[<?php echo $i; ?>]" value="1" />
  505. <input type="hidden" name="attribute_position[<?php echo $i; ?>]" class="attribute_position" value="<?php echo esc_attr( $position ); ?>" />
  506. <div class="inside">
  507. <table>
  508. <tr>
  509. <td class="options">
  510. <input type="text" class="attribute-name" name="attribute_names[<?php echo $i; ?>]" value="<?php echo esc_attr( $label ); ?>" disabled="disabled" />
  511. <div>
  512. <label>
  513. <input type="checkbox" <?php checked(boolval( isset($attribute) ? $attribute['visible'] : 1 ), true); ?> name="attribute_visibility[<?php echo $i; ?>]" value="1" /><?php _e('Display on product page', 'jigoshop'); ?>
  514. </label>
  515. <?php if ($tax->attribute_type!="select") : // always disable variation for select elements ?>
  516. <label class="attribute_is_variable">
  517. <input type="checkbox" <?php checked(boolval( isset($attribute) ? $attribute['variation'] : 0 ), true); ?> name="attribute_variation[<?php echo $i; ?>]" value="1" /><?php _e('Is for variations', 'jigoshop'); ?>
  518. </label>
  519. <?php endif; ?>
  520. </div>
  521. </td>
  522. <td class="value">
  523. <!-- Jigoshop 1.5, 'select' attribute types are no longer retrieved for display -->
  524. <?php if ($tax->attribute_type=="select") : ?>
  525. <select name="attribute_values[<?php echo $i ?>]">
  526. <option value=""><?php _e('Choose an option&hellip;', 'jigoshop'); ?></option>
  527. <?php
  528. if (taxonomy_exists('pa_'.$attribute_taxonomy_name)) :
  529. $terms = get_terms( 'pa_'.$attribute_taxonomy_name, array( 'orderby' => 'slug', 'hide_empty' => '0' ) );
  530. if ($terms) :
  531. foreach ($terms as $term) :
  532. printf('<option value="%s" %s>%s</option>'
  533. , $term->name
  534. , selected(in_array($term->slug, $term_slugs), true, false)
  535. , $term->name);
  536. endforeach;
  537. endif;
  538. endif;
  539. ?>
  540. </select>
  541. <?php elseif ($tax->attribute_type=="multiselect") : ?>
  542. <div class="multiselect">
  543. <?php
  544. if (taxonomy_exists('pa_'.$attribute_taxonomy_name)) :
  545. $terms = get_terms( 'pa_'.$attribute_taxonomy_name, array( 'orderby' => 'slug', 'hide_empty' => '0' ) );
  546. if ($terms) :
  547. foreach ($terms as $term) :
  548. $checked = checked(in_array($term->slug, $term_slugs), true, false);
  549. printf('<label %s><input type="checkbox" name="attribute_values[%d][]" value="%s" %s/> %s</label>'
  550. , !empty($checked) ? 'class="selected"' : ''
  551. , $i
  552. , $term->slug
  553. , $checked
  554. , $term->name);
  555. endforeach;
  556. endif;
  557. endif;
  558. ?>
  559. </div>
  560. <div class="multiselect-controls">
  561. <a class="check-all" href="#"><?php _e('Check All','jigoshop'); ?></a>&nbsp;|
  562. <a class="uncheck-all" href="#"><?php _e('Uncheck All','jigoshop');?></a>&nbsp;|
  563. <a class="toggle" href="#"><?php _e('Toggle','jigoshop');?></a>&nbsp;|
  564. <a class="show-all" href="#"><?php _e('Show All','jigoshop'); ?></a>
  565. </div>
  566. <?php elseif ($tax->attribute_type=="text") : ?>
  567. <textarea name="attribute_values[<?php echo esc_attr( $i ); ?>]"><?php
  568. if ($allterms) :
  569. $prettynames = array();
  570. foreach ($allterms as $term) :
  571. $prettynames[] = $term->name;
  572. endforeach;
  573. echo esc_textarea( implode(',', $prettynames) );
  574. endif;
  575. ?></textarea>
  576. <?php endif; ?>
  577. </td>
  578. </tr>
  579. </table>
  580. </div>
  581. </div>
  582. <?php endforeach; ?>
  583. <?php
  584. // Custom Attributes
  585. if ( $attributes ) foreach ($attributes as $attribute) :
  586. if ($attribute['is_taxonomy']) continue;
  587. $i++;
  588. $position = (isset($attribute['position'])) ? $attribute['position'] : 0;
  589. ?>
  590. <div class="postbox attribute closed <?php echo sanitize_title($attribute['name']); ?>" rel="<?php echo isset($attribute['position']) ? $attribute['position'] : 0; ?>">
  591. <button type="button" class="hide_row button"><?php _e('Remove', 'jigoshop'); ?></button>
  592. <div class="handlediv" title="<?php _e('Click to toggle', 'jigoshop') ?>"><br></div>
  593. <h3 class="handle"><?php echo esc_attr( $attribute['name'] ); ?></h3>
  594. <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?>]" value="0" />
  595. <input type="hidden" name="attribute_enabled[<?php echo $i; ?>]" value="1" />
  596. <input type="hidden" name="attribute_position[<?php echo $i; ?>]" class="attribute_position" value="<?php echo esc_attr( $position ); ?>" />
  597. <div class="inside">
  598. <table>
  599. <tr>
  600. <td class="options">
  601. <input type="text" class="attribute-name" name="attribute_names[<?php echo $i; ?>]" value="<?php echo esc_attr( $attribute['name'] ); ?>" />
  602. <div>
  603. <label>
  604. <input type="checkbox" <?php checked(boolval( isset($attribute) ? $attribute['visible'] : 0 ), true); ?> name="attribute_visibility[<?php echo $i; ?>]" value="1" /><?php _e('Display on product page', 'jigoshop'); ?>
  605. </label>
  606. <label class="attribute_is_variable">
  607. <input type="checkbox" <?php checked(boolval( isset($attribute) ? $attribute['variation'] : 0 ), true); ?> name="attribute_variation[<?php echo $i; ?>]" value="1" /><?php _e('Is for variations', 'jigoshop'); ?>
  608. </label>
  609. </div>
  610. </td>
  611. <td class="value">
  612. <textarea name="attribute_values[<?php echo esc_attr( $i ); ?>]" cols="5" rows="2"><?php echo esc_textarea( apply_filters('jigoshop_product_attribute_value_custom_edit',$attribute['value'], $attribute) ); ?></textarea>
  613. </td>
  614. </tr>
  615. </table>
  616. </div>
  617. </div>
  618. <?php endforeach; ?>
  619. <?php }