/** * Custom Post Types **/ function fflcommerce_post_type() { $options = FFLCommerce_Base::get_options(); $shop_page_id = fflcommerce_get_page_id('shop'); $base_slug = $shop_page_id && ($base_page = get_post($shop_page_id)) ? get_page_uri($shop_page_id) : 'shop'; $category_base = $options->get('fflcommerce_prepend_shop_page_to_urls') == 'yes' ? trailingslashit($base_slug) : ''; $category_slug = $options->get('fflcommerce_product_category_slug') ? $options->get('fflcommerce_product_category_slug') : _x('product-category', 'slug', 'fflcommerce'); $tag_slug = $options->get('fflcommerce_product_tag_slug') ? $options->get('fflcommerce_product_tag_slug') : _x('product-tag', 'slug', 'fflcommerce'); $product_base = $options->get('fflcommerce_prepend_shop_page_to_product') == 'yes' ? trailingslashit($base_slug) : trailingslashit(_x('product', 'slug', 'fflcommerce')); if ($options->get('fflcommerce_prepend_shop_page_to_product') == 'yes' && $options->get('fflcommerce_prepend_shop_page_to_urls') == 'yes') { $product_base .= trailingslashit(_x('product', 'slug', 'fflcommerce')); } if ($options->get('fflcommerce_prepend_category_to_product') == 'yes') { $product_base .= trailingslashit('%product_cat%'); } $product_base = untrailingslashit($product_base); register_post_type("product", array('labels' => array('name' => __('Products', 'fflcommerce'), 'singular_name' => __('Product', 'fflcommerce'), 'all_items' => __('All Products', 'fflcommerce'), 'add_new' => __('Add New', 'fflcommerce'), 'add_new_item' => __('Add New Product', 'fflcommerce'), 'edit' => __('Edit', 'fflcommerce'), 'edit_item' => __('Edit Product', 'fflcommerce'), 'new_item' => __('New Product', 'fflcommerce'), 'view' => __('View Product', 'fflcommerce'), 'view_item' => __('View Product', 'fflcommerce'), 'search_items' => __('Search Products', 'fflcommerce'), 'not_found' => __('No Products found', 'fflcommerce'), 'not_found_in_trash' => __('No Products found in trash', 'fflcommerce'), 'parent' => __('Parent Product', 'fflcommerce')), 'description' => __('This is where you can add new products to your store.', 'fflcommerce'), 'public' => true, 'show_ui' => true, 'capability_type' => 'product', 'map_meta_cap' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'hierarchical' => false, 'rewrite' => array('slug' => $product_base, 'with_front' => false, 'feeds' => $base_slug), 'query_var' => true, 'supports' => array('title', 'editor', 'thumbnail', 'comments', 'excerpt'), 'has_archive' => $base_slug, 'show_in_nav_menus' => false, 'menu_position' => 56, 'menu_icon' => 'dashicons-book')); register_post_type("product_variation", array('labels' => array('name' => __('Variations', 'fflcommerce'), 'singular_name' => __('Variation', 'fflcommerce'), 'add_new' => __('Add Variation', 'fflcommerce'), 'add_new_item' => __('Add New Variation', 'fflcommerce'), 'edit' => __('Edit', 'fflcommerce'), 'edit_item' => __('Edit Variation', 'fflcommerce'), 'new_item' => __('New Variation', 'fflcommerce'), 'view' => __('View Variation', 'fflcommerce'), 'view_item' => __('View Variation', 'fflcommerce'), 'search_items' => __('Search Variations', 'fflcommerce'), 'not_found' => __('No Variations found', 'fflcommerce'), 'not_found_in_trash' => __('No Variations found in trash', 'fflcommerce'), 'parent' => __('Parent Variation', 'fflcommerce')), 'public' => false, 'show_ui' => false, 'publicly_queryable' => true, 'exclude_from_search' => true, 'show_in_nav_menus' => false, 'capability_type' => 'product', 'map_meta_cap' => true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('title', 'editor', 'custom-fields'), 'show_in_menu' => 'edit.php?post_type=product')); register_taxonomy('product_type', array('product'), array('hierarchical' => false, 'show_ui' => false, 'query_var' => true, 'show_in_nav_menus' => false)); register_taxonomy('product_cat', array('product'), array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'labels' => array('menu_name' => __('Categories', 'fflcommerce'), 'name' => __('Product Categories', 'fflcommerce'), 'singular_name' => __('Product Category', 'fflcommerce'), 'search_items' => __('Search Product Categories', 'fflcommerce'), 'all_items' => __('All Product Categories', 'fflcommerce'), 'parent_item' => __('Parent Product Category', 'fflcommerce'), 'parent_item_colon' => __('Parent Product Category:', 'fflcommerce'), 'edit_item' => __('Edit Product Category', 'fflcommerce'), 'update_item' => __('Update Product Category', 'fflcommerce'), 'add_new_item' => __('Add New Product Category', 'fflcommerce'), 'new_item_name' => __('New Product Category Name', 'fflcommerce')), 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => $category_base . $category_slug, 'with_front' => false, 'hierarchical' => false))); register_taxonomy_for_object_type('product_cat', 'product'); register_taxonomy('product_tag', array('product'), array('hierarchical' => false, 'labels' => array('menu_name' => __('Tags', 'fflcommerce'), 'name' => __('Product Tags', 'fflcommerce'), 'singular_name' => __('Product Tag', 'fflcommerce'), 'search_items' => __('Search Product Tags', 'fflcommerce'), 'all_items' => __('All Product Tags', 'fflcommerce'), 'parent_item' => __('Parent Product Tag', 'fflcommerce'), 'parent_item_colon' => __('Parent Product Tag:', 'fflcommerce'), 'edit_item' => __('Edit Product Tag', 'fflcommerce'), 'update_item' => __('Update Product Tag', 'fflcommerce'), 'add_new_item' => __('Add New Product Tag', 'fflcommerce'), 'new_item_name' => __('New Product Tag Name', 'fflcommerce')), 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => $category_base . $tag_slug, 'with_front' => false))); register_taxonomy_for_object_type('product_tag', 'product'); $attribute_taxonomies = fflcommerce_product::getAttributeTaxonomies(); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { $name = 'pa_' . sanitize_title($tax->attribute_name); $hierarchical = true; if ($name) { register_taxonomy($name, array('product'), array('hierarchical' => $hierarchical, 'labels' => array('name' => $tax->attribute_name, 'singular_name' => $tax->attribute_name, 'search_items' => __('Search ', 'fflcommerce') . $tax->attribute_name, 'all_items' => __('All ', 'fflcommerce') . $tax->attribute_name, 'parent_item' => __('Parent ', 'fflcommerce') . $tax->attribute_name, 'parent_item_colon' => __('Parent ', 'fflcommerce') . $tax->attribute_name . ':', 'edit_item' => __('Edit ', 'fflcommerce') . $tax->attribute_name, 'update_item' => __('Update ', 'fflcommerce') . $tax->attribute_name, 'add_new_item' => __('Add New ', 'fflcommerce') . $tax->attribute_name, 'new_item_name' => __('New ', 'fflcommerce') . $tax->attribute_name), 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'show_ui' => false, 'query_var' => true, 'show_in_nav_menus' => false, 'rewrite' => array('slug' => $category_base . sanitize_title($tax->attribute_name), 'with_front' => false, 'hierarchical' => $hierarchical))); } } } register_post_type("shop_order", array('labels' => array('name' => __('Orders', 'fflcommerce'), 'singular_name' => __('Order', 'fflcommerce'), 'all_items' => __('All Orders', 'fflcommerce'), 'add_new' => __('Add New', 'fflcommerce'), 'add_new_item' => __('New Order', 'fflcommerce'), 'edit' => __('Edit', 'fflcommerce'), 'edit_item' => __('Edit Order', 'fflcommerce'), 'new_item' => __('New Order', 'fflcommerce'), 'view' => __('View Order', 'fflcommerce'), 'view_item' => __('View Order', 'fflcommerce'), 'search_items' => __('Search Orders', 'fflcommerce'), 'not_found' => __('No Orders found', 'fflcommerce'), 'not_found_in_trash' => __('No Orders found in trash', 'fflcommerce'), 'parent' => __('Parent Orders', 'fflcommerce')), 'description' => __('This is where store orders are stored.', 'fflcommerce'), 'public' => false, 'show_ui' => true, 'show_in_nav_menus' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'capability_type' => 'shop_order', 'map_meta_cap' => true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('title', 'comments'), 'has_archive' => false, 'menu_position' => 58, 'menu_icon' => 'dashicons-clipboard')); register_taxonomy('shop_order_status', array('shop_order'), array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'labels' => array('name' => __('Order statuses', 'fflcommerce'), 'singular_name' => __('Order status', 'fflcommerce'), 'search_items' => __('Search Order statuses', 'fflcommerce'), 'all_items' => __('All Order statuses', 'fflcommerce'), 'parent_item' => __('Parent Order status', 'fflcommerce'), 'parent_item_colon' => __('Parent Order status:', 'fflcommerce'), 'edit_item' => __('Edit Order status', 'fflcommerce'), 'update_item' => __('Update Order status', 'fflcommerce'), 'add_new_item' => __('Add New Order status', 'fflcommerce'), 'new_item_name' => __('New Order status Name', 'fflcommerce')), 'public' => false, 'show_ui' => false, 'show_in_nav_menus' => false, 'query_var' => true, 'rewrite' => false)); register_post_type("shop_coupon", array('labels' => array('menu_name' => __('Coupons', 'fflcommerce'), 'name' => __('Coupons', 'fflcommerce'), 'singular_name' => __('Coupon', 'fflcommerce'), 'add_new' => __('Add Coupon', 'fflcommerce'), 'add_new_item' => __('Add New Coupon', 'fflcommerce'), 'edit' => __('Edit', 'fflcommerce'), 'edit_item' => __('Edit Coupon', 'fflcommerce'), 'new_item' => __('New Coupon', 'fflcommerce'), 'view' => __('View Coupons', 'fflcommerce'), 'view_item' => __('View Coupon', 'fflcommerce'), 'search_items' => __('Search Coupons', 'fflcommerce'), 'not_found' => __('No Coupons found', 'fflcommerce'), 'not_found_in_trash' => __('No Coupons found in trash', 'fflcommerce'), 'parent' => __('Parent Coupon', 'fflcommerce')), 'description' => __('This is where you can add new coupons that customers can use in your store.', 'fflcommerce'), 'public' => true, 'show_ui' => true, 'capability_type' => 'shop_coupon', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('title', 'editor'), 'show_in_nav_menus' => false, 'show_in_menu' => 'fflcommerce')); register_post_type("shop_email", array('labels' => array('menu_name' => __('Emails', 'fflcommerce'), 'name' => __('Emails', 'fflcommerce'), 'singular_name' => __('Emails', 'fflcommerce'), 'add_new' => __('Add Email', 'fflcommerce'), 'add_new_item' => __('Add New Email', 'fflcommerce'), 'edit' => __('Edit', 'fflcommerce'), 'edit_item' => __('Edit Email', 'fflcommerce'), 'new_item' => __('New Email', 'fflcommerce'), 'view' => __('View Email', 'fflcommerce'), 'view_item' => __('View Email', 'fflcommerce'), 'search_items' => __('Search Email', 'fflcommerce'), 'not_found' => __('No Emils found', 'fflcommerce'), 'not_found_in_trash' => __('No Emails found in trash', 'fflcommerce'), 'parent' => __('Parent Email', 'fflcommerce')), 'description' => __('This is where you can add new emails that customers can receive in your store.', 'fflcommerce'), 'public' => true, 'show_ui' => true, 'capability_type' => 'shop_email', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('title', 'editor'), 'show_in_nav_menus' => false, 'show_in_menu' => 'fflcommerce')); if ($options->get('fflcommerce_update_rewrite_rules') == '1') { // Re-generate rewrite rules global $wp_rewrite; $wp_rewrite->flush_rules(); $options->set('fflcommerce_update_rewrite_rules', '0'); } }
function display_attribute() { global $post; // TODO: This needs refactoring // This is getting all the taxonomies $attribute_taxonomies = fflcommerce_product::getAttributeTaxonomies(); // Sneaky way of doing sort by desc $attribute_taxonomies = array_reverse($attribute_taxonomies); // This is whats applied to the product $attributes = get_post_meta($post->ID, 'product_attributes', true); $i = -1; foreach ($attribute_taxonomies as $tax) { $i++; $attribute = array(); $attribute_taxonomy_name = sanitize_title($tax->attribute_name); if (isset($attributes[$attribute_taxonomy_name])) { $attribute = $attributes[$attribute_taxonomy_name]; } $position = isset($attribute['position']) ? $attribute['position'] : -1; if ($position >= 0) { $allterms = wp_get_object_terms($post->ID, 'pa_' . $attribute_taxonomy_name, array('orderby' => 'slug')); } else { $allterms = array(); } $has_terms = !(is_wp_error($allterms) || empty($allterms)); $term_slugs = array(); if (!is_wp_error($allterms) && !empty($allterms)) { foreach ($allterms as $term) { $term_slugs[] = $term->slug; } } ?> <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"'; } ?> > <button type="button" class="hide_row button"><?php _e('Remove', 'fflcommerce'); ?> </button> <div class="handlediv" title="<?php _e('Click to toggle', 'fflcommerce'); ?> "><br></div> <h3 class="handle"> <?php $label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name; echo esc_attr($label); ?> </h3> <input type="hidden" name="attribute_names[<?php echo $i; ?> ]" value="<?php echo esc_attr(sanitize_title($tax->attribute_name)); ?> " /> <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?> ]" value="1" /> <input type="hidden" name="attribute_enabled[<?php echo $i; ?> ]" value="1" /> <input type="hidden" name="attribute_position[<?php echo $i; ?> ]" class="attribute_position" value="<?php echo esc_attr($position); ?> " /> <div class="inside"> <table> <tr> <td class="options"> <input type="text" class="attribute-name" name="attribute_names[<?php echo $i; ?> ]" value="<?php echo esc_attr($label); ?> " disabled="disabled" /> <div> <label> <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', 'fflcommerce'); ?> </label> <?php if ($tax->attribute_type != "select") { // always disable variation for select elements ?> <label class="attribute_is_variable"> <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', 'fflcommerce'); ?> </label> <?php } ?> </div> </td> <td class="value"> <?php if ($tax->attribute_type == "select") { ?> <select name="attribute_values[<?php echo $i; ?> ]"> <option value=""><?php _e('Choose an option…', 'fflcommerce'); ?> </option> <?php if (taxonomy_exists('pa_' . $attribute_taxonomy_name)) { $terms = get_terms('pa_' . $attribute_taxonomy_name, array('orderby' => 'slug', 'hide_empty' => '0')); if ($terms) { foreach ($terms as $term) { printf('<option value="%s" %s>%s</option>', $term->name, selected(in_array($term->slug, $term_slugs), true, false), $term->name); } } } ?> </select> <?php } elseif ($tax->attribute_type == "multiselect") { ?> <div class="multiselect"> <?php if (taxonomy_exists('pa_' . $attribute_taxonomy_name)) { $terms = get_terms('pa_' . $attribute_taxonomy_name, array('orderby' => 'slug', 'hide_empty' => '0')); if ($terms) { foreach ($terms as $term) { $checked = checked(in_array($term->slug, $term_slugs), true, false); printf('<label %s><input type="checkbox" name="attribute_values[%d][]" value="%s" %s/> %s</label>', !empty($checked) ? 'class="selected"' : '', $i, $term->slug, $checked, $term->name); } } } ?> </div> <div class="multiselect-controls"> <a class="check-all" href="#"><?php _e('Check All', 'fflcommerce'); ?> </a> | <a class="uncheck-all" href="#"><?php _e('Uncheck All', 'fflcommerce'); ?> </a> | <a class="toggle" href="#"><?php _e('Toggle', 'fflcommerce'); ?> </a> | <a class="show-all" href="#"><?php _e('Show All', 'fflcommerce'); ?> </a> </div> <?php } elseif ($tax->attribute_type == "text") { ?> <textarea name="attribute_values[<?php echo esc_attr($i); ?> ]"><?php if ($allterms) { $prettynames = array(); foreach ($allterms as $term) { $prettynames[] = $term->name; } echo esc_textarea(implode(',', $prettynames)); } ?> </textarea> <?php } ?> </td> </tr> </table> </div> </div> <?php } ?> <?php // Custom Attributes if (!empty($attributes)) { foreach ($attributes as $attribute) { if ($attribute['is_taxonomy']) { continue; } $i++; $position = isset($attribute['position']) ? $attribute['position'] : 0; ?> <div class="postbox attribute closed <?php echo sanitize_title($attribute['name']); ?> " rel="<?php echo isset($attribute['position']) ? $attribute['position'] : 0; ?> "> <button type="button" class="hide_row button"><?php _e('Remove', 'fflcommerce'); ?> </button> <div class="handlediv" title="<?php _e('Click to toggle', 'fflcommerce'); ?> "><br></div> <h3 class="handle"><?php echo esc_attr($attribute['name']); ?> </h3> <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?> ]" value="0" /> <input type="hidden" name="attribute_enabled[<?php echo $i; ?> ]" value="1" /> <input type="hidden" name="attribute_position[<?php echo $i; ?> ]" class="attribute_position" value="<?php echo esc_attr($position); ?> " /> <div class="inside"> <table> <tr> <td class="options"> <input type="text" class="attribute-name" name="attribute_names[<?php echo $i; ?> ]" value="<?php echo esc_attr($attribute['name']); ?> " /> <div> <label> <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', 'fflcommerce'); ?> </label> <label class="attribute_is_variable"> <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', 'fflcommerce'); ?> </label> </div> </td> <td class="value"> <textarea name="attribute_values[<?php echo esc_attr($i); ?> ]" cols="5" rows="2"><?php echo esc_textarea(apply_filters('fflcommerce_product_attribute_value_custom_edit', $attribute['value'], $attribute)); ?> </textarea> </td> </tr> </table> </div> </div> <?php } } }
/** * Right Now */ function fflcommerce_dash_right_now() { ?> <div id="fflcommerce_right_now" class="fflcommerce_right_now"> <div class="table table_content"> <p class="sub"><?php echo fflcommerce_prepare_dashboard_title(__('Shop Content', 'fflcommerce')); ?> </p> <table> <tbody> <tr class="first"> <td class="first b"><a href="edit.php?post_type=product"><?php $num_posts = wp_count_posts('product'); $num = number_format_i18n($num_posts->publish); echo $num; ?> </a></td> <td class="t"><a href="edit.php?post_type=product"><?php _e('Products', 'fflcommerce'); ?> </a></td> </tr> <tr> <td class="first b"><a href="edit-tags.php?taxonomy=product_cat&post_type=product"><?php echo wp_count_terms('product_cat'); ?> </a></td> <td class="t"><a href="edit-tags.php?taxonomy=product_cat&post_type=product"><?php _e('Product Categories', 'fflcommerce'); ?> </a></td> </tr> <tr> <td class="first b"><a href="edit-tags.php?taxonomy=product_tag&post_type=product"><?php echo wp_count_terms('product_tag'); ?> </a></td> <td class="t"><a href="edit-tags.php?taxonomy=product_tag&post_type=product"><?php _e('Product Tag', 'fflcommerce'); ?> </a></td> </tr> <tr> <td class="first b"><a href="admin.php?page=fflcommerce_attributes"><?php echo count(fflcommerce_product::getAttributeTaxonomies()); ?> </a></td> <td class="t"><a href="admin.php?page=fflcommerce_attributes"><?php _e('Attribute taxonomies', 'fflcommerce'); ?> </a></td> </tr> </tbody> </table> </div> <div class="table table_discussion"> <p class="sub"><?php fflcommerce_prepare_dashboard_title(__('Orders', 'fflcommerce')); ?> </p> <table> <tbody> <?php $fflcommerce_orders = new fflcommerce_orders(); ?> <tr class="first pending-orders"> <td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=pending"><span class="total-count"><?php echo $fflcommerce_orders->pending_count; ?> </span></a></td> <td class="last t"><a class="pending" href="edit.php?post_type=shop_order&shop_order_status=pending"><?php _e('Pending', 'fflcommerce'); ?> </a></td> </tr> <tr class="on-hold-orders"> <td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=on-hold"><span class="total-count"><?php echo $fflcommerce_orders->on_hold_count; ?> </span></a></td> <td class="last t"><a class="onhold" href="edit.php?post_type=shop_order&shop_order_status=on-hold"><?php _e('On-Hold', 'fflcommerce'); ?> </a></td> </tr> <tr class="processing-orders"> <td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=processing"><span class="total-count"><?php echo $fflcommerce_orders->processing_count; ?> </span></a></td> <td class="last t"><a class="processing" href="edit.php?post_type=shop_order&shop_order_status=processing"><?php _e('Processing', 'fflcommerce'); ?> </a></td> </tr> <tr class="completed-orders"> <td class="b"><a href="edit.php?post_type=shop_order&shop_order_status=completed"><span class="total-count"><?php echo $fflcommerce_orders->completed_count; ?> </span></a> </td> <td class="last t"><a class="complete" href="edit.php?post_type=shop_order&shop_order_status=completed"><?php _e('Completed', 'fflcommerce'); ?> </a></td> </tr> </tbody> </table> </div> <br class="clear" /> </div> <?php }
/** * Order attributes meta box * * Displays a list of all attributes which were selected in the order */ function fflcommerce_order_attributes_meta_box($post) { $order = new fflcommerce_order($post->ID); ?> <ul class="order-attributes"><?php foreach ($order->items as $item_id => $item) { ?> <li> <?php do_action('fflcommerce_order_attributes_meta_box_before_item', $item, $item_id); ?> <b> <?php do_action('fflcommerce_order_attributes_meta_box_before_item_title', $item_id); ?> <?php echo esc_html(isset($item['name']) ? $item['name'] : ''); ?> </b> <?php $taxonomies_count = 0; // process only variations if (isset($item['variation_id']) && !empty($item['variation_id'])) { foreach (fflcommerce_product::getAttributeTaxonomies() as $attr_tax) { $identifier = 'tax_' . $attr_tax->attribute_name; if (!isset($item['variation'][$identifier])) { continue; } $product = new fflcommerce_product_variation($item['variation_id']); $attr_label = str_replace('tax_', '', $identifier); $attr_label = $product->attribute_label('pa_' . $attr_label); $terms = get_terms('pa_' . $attr_tax->attribute_name, array('orderby' => 'slug', 'hide_empty' => false)); ?> <div class="order-item-attribute" style="display:block"> <span style="display:block"><?php echo esc_html($attr_label); ?> </span> <select name="order_attributes[<?php echo $item_id; ?> ][<?php echo $identifier; ?> ]"> <?php foreach ($terms as $term) { ?> <option <?php selected($item['variation'][$identifier], $term->slug); ?> value="<?php echo esc_attr($term->slug); ?> "> <?php echo esc_html($term->name); ?> </option> <?php } ?> </select> </div> <?php $taxonomies_count++; } } if ($taxonomies_count === 0) { ?> <div class="order-item-attribute no-items-in-order" style="display:block"> <?php _e('No attributes for this item.', 'fflcommerce'); ?> </div><?php } do_action('fflcommerce_order_attributes_meta_box_after_item', $item, $item_id); ?> </li><?php } ?> </ul> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function() { jQuery(".order-item-attribute select").select2({ width: '255px' }); }); /*]]>*/ </script> <?php }
/** * Form * Displays the form for the wordpress admin * * @param array instance */ public function form($instance) { // Get values from instance $title = isset($instance['title']) ? esc_attr($instance['title']) : null; $attr_tax = fflcommerce_product::getAttributeTaxonomies(); // Widget title echo '<p>'; echo '<label for="' . esc_attr($this->get_field_id('title')) . '"> ' . _e('Title:', 'fflcommerce') . '</label>'; echo '<input type="text" class="widefat" id="' . esc_attr($this->get_field_id('title')) . '" name="' . esc_attr($this->get_field_name('title')) . '" value="' . esc_attr($title) . '" />'; echo '</p>'; // Print attribute selector if (!empty($attr_tax)) { echo '<p>'; echo '<label for="' . esc_attr($this->get_field_id('attribute')) . '">' . __('Attribute:', 'fflcommerce') . '</label> '; echo '<select id="' . esc_attr($this->get_field_id('attribute')) . '" name="' . esc_attr($this->get_field_name('attribute')) . '">'; foreach ($attr_tax as $tax) { if (taxonomy_exists('pa_' . sanitize_title($tax->attribute_name))) { echo '<option value="' . esc_attr($tax->attribute_name) . '" ' . (isset($instance['attribute']) && $instance['attribute'] == $tax->attribute_name ? 'selected' : null) . '>'; echo $tax->attribute_name; echo '</option>'; } } echo '</select>'; echo '</p>'; } }
/** * Add Attribute admin panel * Shows the interface for adding new attributes * * @since 1.0 * @usedby fflcommerce_attributes() */ function fflcommerce_add_attribute() { ?> <div class="wrap fflcommerce"> <div class="icon32 icon32-attributes" id="icon-fflcommerce"><br /></div> <h2><?php _e('Attributes', 'fflcommerce'); ?> </h2> <br class="clear" /> <div id="col-container"> <div id="col-right"> <div class="col-wrap"> <table class="widefat fixed" style="width:100%"> <thead> <tr> <th scope="col"><?php _e('Label', 'fflcommerce'); ?> </th> <th scope="col"><?php _e('Slug', 'fflcommerce'); ?> </th> <th scope="col"><?php _e('Type', 'fflcommerce'); ?> </th> <th scope="col"> </th> </tr> </thead> <tbody> <?php $attribute_taxonomies = fflcommerce_product::getAttributeTaxonomies(); if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { $att_title = $tax->attribute_name; if (isset($tax->attribute_label)) { $att_title = $tax->attribute_label; } ?> <tr> <td><a href="edit-tags.php?taxonomy=pa_<?php echo sanitize_title($tax->attribute_name); ?> &post_type=product"><?php echo esc_html(ucwords($att_title)); ?> </a> <div class="row-actions"><span class="edit"><a href="<?php echo esc_url(add_query_arg('edit', $tax->attribute_id, 'admin.php?page=fflcommerce_attributes')); ?> "><?php _e('Edit', 'fflcommerce'); ?> </a> | </span><span class="delete"><a class="delete" href="<?php echo esc_url(wp_nonce_url(add_query_arg('delete', $tax->attribute_id, 'admin.php?page=fflcommerce_attributes'), 'fflcommerce-delete-attribute_' . $tax->attribute_id)); ?> "><?php _e('Delete', 'fflcommerce'); ?> </a></span> </div> </td> <td><?php echo $tax->attribute_name; ?> </td> <td><?php echo esc_html(ucwords($tax->attribute_type)); ?> </td> <td><a href="edit-tags.php?taxonomy=pa_<?php echo sanitize_title($tax->attribute_name); ?> &post_type=product" class="button alignright"><?php _e('Configure terms', 'fflcommerce'); ?> </a></td> </tr><?php } } else { ?> <tr> <td colspan="5"><?php _e('No attributes currently exist.', 'fflcommerce'); ?> </td></tr><?php } ?> </tbody> </table> </div> </div> <div id="col-left"> <div class="col-wrap"> <div class="form-wrap"> <h3><?php _e('Add New Attribute', 'fflcommerce'); ?> </h3> <form action="edit.php?post_type=product&page=fflcommerce_attributes" method="post"> <?php wp_nonce_field('fflcommerce-add-attribute', '_fflcommerce_csrf'); ?> <div class="form-field"> <label for="attribute_label"><?php _e('Attribute Label', 'fflcommerce'); ?> </label> <input name="attribute_label" id="attribute_label" type="text" value="" /> <p class="description"><?php _e('The label is how it appears on your site.', 'fflcommerce'); ?> </p> </div> <div class="form-field"> <label for="attribute_name"><?php _e('Attribute Slug', 'fflcommerce'); ?> </label> <input name="attribute_name" id="attribute_name" type="text" value="" /> <p class="description"><?php _e('Slug for your attribute (optional).', 'fflcommerce'); ?> </p> </div> <div class="form-field"> <label for="attribute_type"><?php _e('Attribute type', 'fflcommerce'); ?> </label> <select name="attribute_type" id="attribute_type" class="postform"> <option value="multiselect"><?php _e('Multiselect', 'fflcommerce'); ?> </option> <option value="select"><?php _e('Select', 'fflcommerce'); ?> </option> <option value="text"><?php _e('Text', 'fflcommerce'); ?> </option> </select> </div> <?php do_action('fflcommerce_attribute_admin_add_before_submit'); ?> <p class="submit"><input type="submit" name="add_new_attribute" id="submit" class="button" value="<?php esc_html_e('Add Attribute', 'fflcommerce'); ?> "></p> </form> </div> </div> </div> </div> <script type="text/javascript"> /* <![CDATA[ */ jQuery('a.delete').click(function(){ return confirm("<?php _e('Are you sure you want to delete this?', 'fflcommerce'); ?> "); }); /* ]]> */ </script> </div> <?php }