PageRenderTime 67ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

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

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