function foxyshop_addon_products($show_qty = false, $before_entry = "", $after_entry = '<div class="clr"></div>') { global $foxyshop_settings, $product, $foxyshop_skip_url_link; if (!$foxyshop_settings['enable_addon_products'] || !$product['addon_products']) { return; } $original_product = $product; echo '<div class="foxyshop_addon_container">' . "\n"; $args = array('post_type' => 'foxyshop_product', "post__in" => explode(",", $product['addon_products']), 'posts_per_page' => -1); if ($addonorder_order = get_post_meta($original_product['id'], "_addon_order", 1)) { add_filter('posts_orderby', 'foxyshop_addon_order'); } $addonproducts = new WP_Query($args); if (!$product['bundled_products']) { $num = 2; } else { $bundled_products = explode(",", $product['bundled_products']); $num = count($bundled_products) + 2; } while ($addonproducts->have_posts()) { $addonproducts->the_post(); //Setup $product = foxyshop_setup_product(); //Check Inventory Levels if (isset($product['inventory_levels'][$product['code']]['count'])) { if ($product['inventory_levels'][$product['code']]['count'] <= 0) { continue; } } $fields = array('name', 'price', 'code', 'category', 'weight', 'discount_quantity_amount', 'discount_quantity_percentage', 'discount_price_amount', 'discount_price_percentage', 'sub_frequency', 'sub_startdate', 'sub_enddate'); foreach ($fields as $fieldname) { if ($product[$fieldname]) { echo '<input type="hidden" class="foxyshop_addon_fields" rel="' . $num . '" originalname="' . $fieldname . foxyshop_get_verification($fieldname) . '" name="x:' . $fieldname . foxyshop_get_verification($fieldname) . '" id="' . $num . ':' . $fieldname . '_' . $product['id'] . '" value="' . esc_attr($product[$fieldname]) . '" />' . "\n"; } } if (foxyshop_get_main_image() && version_compare($foxyshop_settings['version'], '0.7.0', ">")) { echo '<input type="hidden" class="foxyshop_addon_fields" rel="' . $num . '" originalname="image' . foxyshop_get_verification('image', '--OPEN--') . '" name="x:image' . foxyshop_get_verification('image', '--OPEN--') . '" id="' . $num . ':image_' . $product['id'] . '" value="' . foxyshop_get_main_image() . '" />' . "\n"; } if (version_compare($foxyshop_settings['version'], '0.7.0', ">") && !isset($foxyshop_skip_url_link)) { echo '<input type="hidden" class="foxyshop_addon_fields" rel="' . $num . '" originalname="url' . foxyshop_get_verification('url') . '" name="x:url' . foxyshop_get_verification('url') . '" id="' . $num . ':url_' . $product['id'] . '" value="' . $product['url'] . '" />' . "\n"; } //Output echo $before_entry; echo '<input type="checkbox" name="x:addon_' . $num . '" id="addon_' . $num . '" rel="' . $num . '" class="foxyshop_addon_checkbox" />'; echo '<label for="addon_' . $num . '" class="addon_main_label">' . $product['name'] . '</label>'; echo '<input type="hidden" name="x:addon_price_' . $num . '" id="addon_price_' . $num . '" value="' . $product['price'] . '" />'; foxyshop_price(0, 1); if ($show_qty) { echo foxyshop_quantity(apply_filters("foxyshop_default_quantity_value", 1), "", "", $num); } echo $after_entry; $num++; } wp_reset_query(); echo '</div>' . "\n"; $product = $original_product; ?> <script type="text/javascript"> function foxyshop_addon_enable(rel) { if ($("#addon_" + rel).is(":checked")) { jQuery(".foxyshop_addon_fields[rel='" + rel + "']").each(function() { jQuery(this).attr("name", rel + ":" + jQuery(this).attr("originalname")); }); jQuery(".foxyshop_quantity.foxyshop_addon_fields[rel=" + rel + "]").prop("disabled", false); } else { jQuery(".foxyshop_addon_fields[rel='" + rel + "']").each(function() { jQuery(this).attr("name", "x:" + jQuery(this).attr("originalname")) }); jQuery(".foxyshop_quantity.foxyshop_addon_fields[rel=" + rel + "]").prop("disabled", true); } } jQuery(document).ready(function($){ $(".foxyshop_addon_checkbox").click(function() { foxyshop_addon_enable($(this).attr("rel")); }); $("input.foxyshop_quantity.foxyshop_addon_fields").keyup(function() { $(this).val($(this).val().replace(/\D/g,'')); $(".foxyshop_addon_checkbox").trigger("change"); }); }); </script> <?php remove_filter('posts_orderby', 'foxyshop_addon_order'); }
//Show a sale tag if the product is on sale //if (foxyshop_is_on_sale()) echo '<p>SALE!</p>'; //Product Is New Tag (number of days since added) //if (foxyshop_is_product_new(14)) echo '<p>NEW!</p>'; //Main Product Description echo $product['description']; //Show Variations (showQuantity: 0 = Do Not Show Qty, 1 = Show Before Variations, 2 = Show Below Variations) foxyshop_product_variations(2); //(style) clear floats before the submit button echo '<div class="clr"></div>'; //Check Inventory Levels and Display Status (last variable allows ordering of out of stock items) foxyshop_inventory_management("There are only %c item%s left in stock.", "Item is not in stock.", false); //Add On Products ($qty, $before_entry, $after_entry) foxyshop_addon_products(true); //Add To Cart Button echo '<button type="submit" name="x:productsubmit" id="productsubmit" class="foxyshop_button">Add To Cart</button>'; //Shows the Price (includes sale price if applicable) echo '<div id="foxyshop_main_price">'; foxyshop_price(); echo '</div>'; //Shows any related products foxyshop_related_products("Related Products"); //Custom Code Can Go Here //Ends the form echo '</div>'; echo '</form>'; ?> <div class="clr"></div> </div> <?php foxyshop_include('footer');
function foxyshop_custom_sort() { global $wpdb, $product; $parentID = 0; $success = ""; //Reset Order if (isset($_GET['upgrade_menu_order'])) { foxyshop_upgrade_menu_order(); } if (isset($_POST['submit_new_product_order'])) { if (check_admin_referer('update-foxyshop-sorting-options')) { $success = foxyshop_update_order(); } } elseif (isset($_POST['revert_product_order'])) { if (check_admin_referer('update-foxyshop-sorting-options')) { $success = foxyshop_revert_order(); } } ?> <div class="wrap"> <div class="icon32" id="icon-tools"><br></div> <h2><?php echo sprintf(__('Custom %s Order'), FOXYSHOP_PRODUCT_NAME_SINGULAR); ?> </h2> <?php if ($success) { echo $success; } ?> <?php $product_categories = get_terms('foxyshop_categories', 'hide_empty=0&hierarchical=0&orderby=name&order=ASC'); $categoryID = 0; if (isset($_REQUEST['categoryID'])) { $categoryID = $_REQUEST['categoryID']; } if ($product_categories) { echo '<p>' . sprintf(__("Select a category from the drop down to order the %s in that category.", 'foxyshop'), strtolower(FOXYSHOP_PRODUCT_NAME_PLURAL)) . "</p>\n"; echo '<form name="form_product_category_order" method="post" action="edit.php?post_type=foxyshop_product&page=foxyshop_custom_sort">'; echo '<select name="categoryID" id="categoryID">' . "\n"; echo '<option value="0"' . ($categoryID == 0 ? ' selected="selected"' : '') . '>' . __('All', 'foxyshop') . ' ' . FOXYSHOP_PRODUCT_NAME_PLURAL . '</option>' . "\n"; foreach ($product_categories as $cat) { echo '<option value="' . esc_attr($cat->term_id) . '"' . ($categoryID == $cat->term_id ? ' selected="selected"' : '') . '>' . esc_html($cat->name) . ' (' . $cat->count . ')' . '</option>' . "\n"; } echo '</select>' . "\n"; echo '<input type="submit" name="btnSubPages" class="button" id="btnSubPages" value="' . __('Select Category', 'foxyshop') . '" /></form>'; } else { $categoryID = 0; } if ($categoryID >= 0) { if ($categoryID > 0) { $term = get_term_by('id', $categoryID, "foxyshop_categories"); $current_category_name = $term->name; $args = array('post_type' => 'foxyshop_product', 'foxyshop_categories' => $term->slug, 'posts_per_page' => -1, 'orderby' => "meta_value_num", "meta_key" => "_foxyshop_menu_order_" . $categoryID, 'order' => "ASC", 'post__not_in' => foxyshop_hide_children_array($categoryID)); } else { $current_category_name = __("All", 'foxyshop') . ' ' . FOXYSHOP_PRODUCT_NAME_PLURAL; $args = array('post_type' => 'foxyshop_product', 'numberposts' => -1, 'orderby' => "menu_order", 'order' => "ASC"); } $product_list = get_posts($args); if ($product_list) { echo '<h3>' . $current_category_name . '</h3>' . "\n"; echo '<p>' . sprintf(__('Drag %s to the preferred order and then click the Save button at the bottom of the page.', 'foxyshop'), strtolower(FOXYSHOP_PRODUCT_NAME_PLURAL)) . '</p>'; echo '<form name="form_product_order" method="post" action="">' . "\n"; echo '<ul id="foxyshop_product_order_list" class="foxyshop_sort_list">' . "\n"; foreach ($product_list as $prod) { $product = foxyshop_setup_product($prod); if ($categoryID == 0) { $current_count = $prod->menu_order; } else { $current_count = (int) get_post_meta($prod->ID, "_foxyshop_menu_order_" . $categoryID, true); } echo '<li id="id_' . $prod->ID . '" class="lineitem">'; echo '<img src="' . foxyshop_get_main_image() . '" />'; echo '<h4>' . $prod->post_title . '</h4>' . "\n"; echo foxyshop_price(); echo '<div class="counter">' . ($current_count + 1) . '</div>'; echo '<div style="clear: both; height: 1px;"></div>' . "\n"; echo '</li>' . "\n"; } echo '</ul>' . "\n"; ?> <div style="width: 90%; height: 100px;"> <input type="submit" name="submit_new_product_order" id="submit_new_product_order" class="button-primary" value="<?php _e('Save Custom Order', 'foxyshop'); ?> " onclick="javascript:orderPages(); return true;" /> <strong id="updateText"></strong> <input type="submit" name="revert_product_order" id="revert_product_order" class="button" style="float: right;" value="<?php _e('Revert To Original', 'foxyshop'); ?> " onclick="javascript:orderPages(); return true;" /> </div> <input type="hidden" id="foxyshop_product_order_value" name="foxyshop_product_order_value" /> <input type="hidden" id="hdnParentID" name="hdnParentID" value="<?php echo $parentID; ?> " /> <input type="hidden" id="categoryID" name="categoryID" value="<?php echo $categoryID; ?> " /> <?php wp_nonce_field('update-foxyshop-sorting-options'); ?> </form> <?php } else { echo '<p><em>' . sprintf(__('No %s Found For This Category.', 'foxyshop'), FOXYSHOP_PRODUCT_NAME_PLURAL) . '</em></p>'; echo '<p><a href="edit.php?post_type=foxyshop_product&page=foxyshop_custom_sort&upgrade_menu_order=1&categoryID=' . $categoryID . '">Missing products? Click here.</a></p>'; } } ?> </div> <script type="text/javascript"> function foxyshop_custom_order_load_event(){ jQuery("#foxyshop_product_order_list").sortable({ placeholder: "sortable-placeholder", revert: false, tolerance: "pointer", update: function() { var counter = 1; jQuery("#foxyshop_product_order_list li").each(function() { jQuery(this).find('.counter').html(counter); counter++; }); } }); }; addLoadEvent(foxyshop_custom_order_load_event); function orderPages() { jQuery("#updateText").html("<?php echo sprintf(__('Updating %s Order...', 'foxyshop'), FOXYSHOP_PRODUCT_NAME_SINGULAR); ?> "); jQuery("#foxyshop_product_order_value").val(jQuery("#foxyshop_product_order_list").sortable("toArray")); } </script> <?php }