public function column_default($item, $column_name) { global $product; if (!$product || $product->id !== $item->id) { $product = new jigoshop_product($item->id); } switch ($column_name) { case 'product': if ($sku = $product->get_sku()) { echo $sku . ' - '; } echo $product->get_title(); // Get variation data if ($product->is_type('variation')) { $list_attributes = array(); $attributes = $product->get_available_attributes_variations(); foreach ($attributes as $name => $attribute) { $list_attributes[] = $product->attribute_label(str_replace('pa_', '', $name)) . ': <strong>' . $attribute . '</strong>'; } echo '<div class="description">' . implode(', ', $list_attributes) . '</div>'; } break; case 'parent': if ($item->parent) { echo get_the_title($item->parent); } else { echo '-'; } break; case 'stock_status': if ($product->is_in_stock() || !isset($product->meta['stock_manage']) && !isset($product->meta['stock_status']) && $product->get_stock() > 0) { echo '<mark class="instock">' . __('In stock', 'jigoshop') . '</mark>'; } else { echo '<mark class="outofstock">' . __('Out of stock', 'jigoshop') . '</mark>'; } break; case 'stock_level': echo $product->get_stock(); break; case 'actions': ?> <p> <?php $actions = array(); $action_id = $item->parent != 0 ? $item->parent : $item->id; $actions['edit'] = array('url' => admin_url('post.php?post=' . $action_id . '&action=edit'), 'name' => __('Edit', 'jigoshop'), 'action' => "edit"); if ($product->is_visible()) { $actions['view'] = array('url' => get_permalink($action_id), 'name' => __('View', 'jigoshop'), 'action' => "view"); } $actions = apply_filters('jigoshop_admin_stock_report_product_actions', $actions, $product); foreach ($actions as $action) { printf('<a class="button tips %s" href="%s" data-tip="%s ' . __('product', 'jigoshop') . '">%s</a>', $action['action'], esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name'])); } ?> </p><?php break; } }
public function display() { global $post; // Get the attributes $attributes = (array) maybe_unserialize(get_post_meta($post->ID, 'product_attributes', true)); // Get all variations of the product $variations = get_posts(array('post_type' => 'product_variation', 'post_status' => array('draft', 'publish'), 'numberposts' => -1, 'orderby' => 'id', 'order' => 'asc', 'post_parent' => $post->ID)); ?> <div id='variable_product_options' class='panel'> <?php if ($this->has_variable_attributes($attributes)) { ?> <div class="toolbar"> <select name="variation_actions"> <option value="default"><?php _e('Bulk Actions', 'jigoshop'); ?> </option> <option value="remove_all"><?php _e('Remove All Variations', 'jigoshop'); ?> </option> <optgroup label="<?php _e('Set All', 'jigoshop'); ?> :"> <option value="set_all_regular_prices"><?php _e('Regular Prices', 'jigoshop'); ?> </option> <option value="set_all_sale_prices"><?php _e('Sale Prices', 'jigoshop'); ?> </option> <option value="set_all_stock"><?php _e('Stock', 'jigoshop'); ?> </option> <option value="set_all_weight"><?php _e('Weight', 'jigoshop'); ?> </option> <option value="set_all_width"><?php _e('Width', 'jigoshop'); ?> </option> <option value="set_all_length"><?php _e('Length', 'jigoshop'); ?> </option> <option value="set_all_height"><?php _e('Height', 'jigoshop'); ?> </option> </optgroup> </select> <input id="do_actions" type="submit" class="button-secondary" value="<?php _e('Apply', 'jigoshop'); ?> "> <button type='button' class='button button-seconday add_variation'><?php _e('Add Variation', 'jigoshop'); ?> </button> </div> <?php } ?> <div class='jigoshop_variations'> <?php if ($this->has_variable_attributes($attributes)) { ?> <?php if ($variations) { foreach ($variations as $variation) { echo $this->generate_panel($attributes, $variation); } } ?> <?php } ?> </div> <div class="toolbar"> <strong><?php _e('Default selections:', 'jigoshop'); ?> </strong> <?php $default_attributes = (array) maybe_unserialize(get_post_meta($post->ID, '_default_attributes', true)); foreach ($attributes as $attr) { // If not variable attribute then skip if (!isset($attr['variation'])) { continue; } // Get current value for variation (if set) $selected = isset($default_attributes[sanitize_title($attr['name'])]) ? $default_attributes[sanitize_title($attr['name'])] : ''; // Open the select & set a default value echo '<select name="default_attribute_' . sanitize_title($attr['name']) . '" >'; $product = new jigoshop_product($post->ID); echo '<option value="">' . __('No default', 'jigoshop') . ' ' . $product->attribute_label('pa_' . $attr['name']) . '…</option>'; // Get terms for attribute taxonomy or value if its a custom attribute if ($attr['is_taxonomy']) { $options = wp_get_object_terms($post->ID, 'pa_' . sanitize_title($attr['name']), array('orderby' => 'slug')); if (!is_wp_error($options)) { foreach ($options as $option) { echo '<option value="' . esc_attr($option->slug) . '" ' . selected($selected, $option->slug, false) . '>' . $option->name . '</option>'; } } } else { $options = explode(',', $attr['value']); foreach ($options as $option) { $option = trim($option); echo '<option ' . selected($selected, $option, false) . ' value="' . esc_attr($option) . '">' . $option . '</option>'; } } // Close the select echo '</select>'; } ?> </div> </div> <?php }
/** Show variation info if set * * @param jigoshop_product $product * @param array $variation_data * @param bool $flat * @return string */ function jigoshop_get_formatted_variation(jigoshop_product $product, $variation_data = array(), $flat = false) { $return = ''; if (!is_array($variation_data)) { $variation_data = array(); } if ($product instanceof jigoshop_product_variation) { $variation_data = array_merge(array_filter($variation_data), array_filter($product->variation_data)); if (!$flat) { $return = '<dl class="variation">'; } $variation_list = array(); $added = array(); foreach ($variation_data as $name => $value) { if (empty($value)) { continue; } $name = str_replace('tax_', '', $name); if (in_array($name, $added)) { continue; } $added[] = $name; if (taxonomy_exists('pa_' . $name)) { $terms = get_terms('pa_' . $name, array('orderby' => 'slug', 'hide_empty' => '0')); foreach ($terms as $term) { if ($term->slug == $value) { $value = $term->name; } } $name = get_taxonomy('pa_' . $name)->labels->name; $name = $product->attribute_label('pa_' . $name); } // TODO: if it is a custom text attribute, 'pa_' taxonomies are not created and we // have no way to get the 'label' as submitted on the Edit Product->Attributes tab. // (don't ask me why not, I don't know, but it seems that we should be creating taxonomies) // this function really requires the product passed to it for: $product->attribute_label( $name ) if ($flat) { $variation_list[] = $name . ': ' . $value; } else { $variation_list[] = '<dt>' . $name . ':</dt><dd>' . $value . '</dd>'; } } if ($flat) { $return .= implode(', ', $variation_list); } else { $return .= implode('', $variation_list); } if (!$flat) { $return .= '</dl>'; } } return $return; }