/** * Add order item via ajax * * @access public * @return void */ function woocommerce_add_order_item() { global $woocommerce, $wpdb; check_ajax_referer('add-order-item', 'security'); $index = trim(stripslashes($_POST['index'])); $item_to_add = trim(stripslashes($_POST['item_to_add'])); $post = ''; // Find the item if (is_numeric($item_to_add)) { $post = get_post($item_to_add); } if (!$post || $post->post_type !== 'product' && $post->post_type !== 'product_variation') { $post_id = $wpdb->get_var($wpdb->prepare("\r\n\t\t\tSELECT post_id\r\n\t\t\tFROM {$wpdb->posts}\r\n\t\t\tLEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)\r\n\t\t\tWHERE {$wpdb->postmeta}.meta_key = '_sku'\r\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\r\n\t\t\tAND {$wpdb->posts}.post_type = 'shop_product'\r\n\t\t\tAND {$wpdb->postmeta}.meta_value = %s\r\n\t\t\tLIMIT 1\r\n\t\t"), $item_to_add); $post = get_post($post_id); } if (!$post || $post->post_type !== 'product' && $post->post_type !== 'product_variation') { die; } if ($post->post_type == "product") { $_product = new WC_Product($post->ID); } else { $_product = new WC_Product_Variation($post->ID); } ?> <tr class="item" rel="<?php echo $index; ?> "> <td class="thumb"> <a href="<?php echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit')); ?> " class="tips" data-tip="<?php echo '<strong>' . __('Product ID:', 'woocommerce') . '</strong> ' . $_product->id; echo '<br/><strong>' . __('Variation ID:', 'woocommerce') . '</strong> '; if (isset($_product->variation_id) && $_product->variation_id) { echo $_product->variation_id; } else { echo '-'; } echo '<br/><strong>' . __('Product SKU:', 'woocommerce') . '</strong> '; if ($_product->sku) { echo $_product->sku; } else { echo '-'; } ?> "><?php echo $_product->get_image(); ?> </a> </td> <td class="sku" width="1%"> <?php if ($_product->sku) { echo $_product->sku; } else { echo '-'; } ?> <input type="hidden" class="item_id" name="item_id[<?php echo $index; ?> ]" value="<?php echo esc_attr($_product->id); ?> " /> <input type="hidden" name="item_name[<?php echo $index; ?> ]" value="<?php echo esc_attr($_product->get_title()); ?> " /> <input type="hidden" name="item_variation[<?php echo $index; ?> ]" value="<?php if (isset($_product->variation_id)) { echo $_product->variation_id; } ?> " /> </td> <td class="name"> <div class="row-actions"> <span class="trash"><a class="remove_row" href="#"><?php _e('Delete item', 'woocommerce'); ?> </a> | </span> <span class="view"><a href="<?php echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit')); ?> "><?php _e('View product', 'woocommerce'); ?> </a> </div> <?php echo $_product->get_title(); ?> <?php if (isset($_product->variation_data)) { echo '<br/>' . woocommerce_get_formatted_variation($_product->variation_data, true); } ?> <table class="meta" cellspacing="0"> <tfoot> <tr> <td colspan="3"><button class="add_meta button"><?php _e('Add meta', 'woocommerce'); ?> </button></td> </tr> </tfoot> <tbody class="meta_items"></tbody> </table> </td> <?php do_action('woocommerce_admin_order_item_values', $_product); ?> <td class="tax_class" width="1%"> <select class="tax_class" name="item_tax_class[<?php echo $loop; ?> ]"> <?php $tax_classes = array_filter(array_map('trim', explode("\n", get_option('woocommerce_tax_classes')))); $classes_options = array(); $classes_options[''] = __('Standard', 'woocommerce'); if ($tax_classes) { foreach ($tax_classes as $class) { $classes_options[sanitize_title($class)] = $class; } } foreach ($classes_options as $value => $name) { echo '<option value="' . $value . '" ' . selected($value, $_product->get_tax_status(), false) . '>' . $name . '</option>'; } ?> </select> </td> <td class="quantity" width="1%"> <input type="text" name="item_quantity[<?php echo $index; ?> ]" placeholder="0" value="1" size="2" class="quantity" /> </td> <td class="line_subtotal" width="1%"> <label><?php _e('Cost', 'woocommerce'); ?> : <input type="text" name="line_subtotal[<?php echo $index; ?> ]" placeholder="0.00" value="<?php echo esc_attr(number_format((double) $_product->get_price_excluding_tax(), 2, '.', '')); ?> " class="line_subtotal" /></label> <label><?php _e('Tax', 'woocommerce'); ?> : <input type="text" name="line_subtotal_tax[<?php echo $index; ?> ]" placeholder="0.00" class="line_subtotal_tax" /></label> </td> <td class="line_total" width="1%"> <label><?php _e('Cost', 'woocommerce'); ?> : <input type="text" name="line_total[<?php echo $index; ?> ]" placeholder="0.00" value="<?php echo esc_attr(number_format((double) $_product->get_price_excluding_tax(), 2, '.', '')); ?> " class="line_total" /></label> <label><?php _e('Tax', 'woocommerce'); ?> : <input type="text" name="line_tax[<?php echo $index; ?> ]" placeholder="0.00" class="line_tax" /></label> </td> </tr> <?php // Quit out die; }
function get_inventory() { $options = get_option('alterinventory_options'); $out = !isset($options['<h1 style="color:#F00">errormessage_template</h1>']) || $options['<h1 style="color:#F00">errormessage_template</h1>'] == "" ? '<h1 style="color:#F00">This section is not allowed to users. Please contact the administrator to request the access!</h1>' : $options['errormessage_template']; $out = get_option('<h1 style="color:#F00">alterinventory_error_message</h1>', '<h1 style="color:#F00">This section is not allowed to users. Please contact the administrator to request the access!</h1>'); $user = wp_get_current_user(); if (empty($user->ID)) { echo $out; } if (!is_user_logged_in()) { wp_login_form(); } else { global $woocommerce, $woo_options; ?> <div> <div align="right" style="margin-bottom:-64px" > <script type="text/javascript"> function printPage(){ var tableData = '<table border="1">'+document.getElementsByTagName('table')[0].innerHTML+'</table>'; var data = '<button onclick="window.print()"><?php echo __('Print', 'woocommerce-alter-inventory'); ?> </button>'+tableData; myWindow=window.open('','','width=1000,height=800px'); myWindow.innerWidth = screen.width; myWindow.innerHeight = screen.height; myWindow.screenX = 0; myWindow.screenY = 0; myWindow.document.write(data); myWindow.focus(); }; </script> <br /> <a href="javascript:void(0);" class="button" type="submit" id="printPage" onclick="printPage();"><?php echo __('Print', 'woocommerce-alter-inventory'); ?> </a> | <a href="alter-inventory/" class="button" type="submit" ><?php echo __('Update', 'woocommerce-alter-inventory'); ?> </a> </div> <div align="left" > </div> </div> <h2><?php echo __('VARIATIONS', 'woocommerce-alter-inventory'); ?> </h2> <table width="100%" style="border: 1px solid #000; width: 100%; margin-bottom: 50px" cellspacing="0" cellpadding="2" > <thead > <tr> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('IMAGE', 'woothemes'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('VARIABLE', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('PRODUCT', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('SKU', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('PRICE', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('SELL PRICE', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('ATTRIBUTE', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:right; border: 1px solid #000; padding: 6px;"><?php _e('STOCK', 'woocommerce-alter-inventory'); ?> </th> <th class="order-number" scope="col"><?php _e('BUY', 'woothemes'); ?> </th> </tr> </thead> <tbody> <?php $args = array('post_type' => 'product_variation', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC'); // Loop Product Variation $loop = new WP_Query($args); while ($loop->have_posts()) { $loop->the_post(); $product = new WC_Product_Variation($loop->post->ID); $attrs = array(); if ($product->variation_data != "") { $terms = wc_get_attribute_taxonomies(); foreach ($terms as $term) { $termMap['attribute_pa_' . $term->attribute_name] = $term->attribute_label; } foreach ($product->variation_data as $attributeKey => $value) { if (isset($termMap[$attributeKey])) { $attrs[] = $termMap[$attributeKey] . " : " . $value; } else { $attrs[] = $value; } } } /* $colore = get_post_meta( get_the_ID(), 'attribute_pa_color', true ); $taglia = get_post_meta( get_the_ID(), 'attribute_pa_taglia', true ); */ ?> <tr class="order"> <td class="thumb column-thumb" ><?php echo $product->get_image($size = 'shop_thumbnail'); ?> </td> <td class="order-number" style="text-transform:uppercase"><?php echo $product->get_title(); ?> </td> <td class="order-number"><?php echo get_the_title($loop->post->post_parent); ?> </td> <td class="order-number"><?php echo $product->sku; ?> </td> <td class="order-number"><?php echo $product->regular_price; ?> <strong>€</strong></td> <td class="order-number" style="color:#F00"><?php echo $product->sale_price; ?> </td> <td class="order-number" style="text-transform:uppercase"><?php echo join("<strong> / </strong>", $attrs); ?> </td> <td class="order-number"><?php echo $product->stock; ?> <strong>pezzi</strong></td> <td style="float:right;" class="order-number"><?php echo apply_filters('woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>', esc_url($product->add_to_cart_url('/alter-inventory/')), esc_attr($product->id), esc_attr($product->get_sku()), $product->is_purchasable() ? 'add_to_cart_button' : '', esc_attr($product->product_type), esc_html($product->add_to_cart_text())), $product); ?> </td> </tr> <?php } ?> </tbody> </table> <style> .shipping_calculator, .cart-collaterals, .woocommerce-info {display: none;} .hentry img { height: auto; max-width: 35%;} h2 { padding-top: 20px;} .woocommerce-message { display:none;} .customer_details, .col2-set { display:none;} #reviews {display: none;} </style> <h2><?php echo __('PRODUCTS', 'woocommerce-alter-inventory'); ?> </h2> <table width="100%" style="border: 1px solid #000; width: 100%; margin-bottom: 50px" cellspacing="0" cellpadding="2" > <thead> <tr> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('IMAGE', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('PRODUCT', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('SKU', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('PRICE', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('SELL PRICE', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('STOCK', 'woocommerce-alter-inventory'); ?> </th> <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php _e('BUY', 'woocommerce-alter-inventory'); ?> </th> </tr> </thead> <tbody> <?php $args2 = array('post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'tax_query' => array(array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => array('simple'), 'operator' => 'IN'))); $loop = new WP_Query($args2); while ($loop->have_posts()) { $loop->the_post(); global $product; ?> <tr > <td class="thumb column-thumb" ><?php echo $product->get_image($size = 'shop_thumbnail'); ?> </td> <td class="order-number" style="text-transform:uppercase"><?php echo $product->get_title(); ?> </td> <td class="order-number"><?php echo $product->sku; ?> </td> <td class="order-number"><?php echo $product->price; ?> </td> <td class="order-number" style="color:#F00"><?php echo $product->sale_price; ?> </td> <td class="order-number"><?php echo $product->stock; ?> </td> <td class="order-number" meta http-equiv="refresh" content="0; url=/alter-inventory/" /><?php echo apply_filters('woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s" >%s</a>', esc_url($product->add_to_cart_url('alter-inventory/')), esc_attr($product->id), esc_attr($product->get_sku()), $product->is_purchasable() ? 'add_to_cart_button' : '', esc_attr($product->product_type), esc_html($product->add_to_cart_text())), $product); ?> <div id="ajax-response"></div> </td> </tr> <?php } ?> </tbody> </table> <div > <h2><?php echo __('PRODUCT SELL', 'woocommerce-alter-inventory'); ?> </h2> </div> <?php echo do_shortcode('[woocommerce_cart]', 'alterinventory'); //Change text in ceckout add_action('woocommerce_order_button_text', 'alter_custom_checkout_text'); function alter_custom_checkout_text() { $text = __('Conclude Sale', 'woocommerce-alter-inventory'); return $text; } ?> <div> <h1 align="center"> <a href="..//alter-inventory/"> <?php echo __('UPDATE PAGE', 'woocommerce-alter-inventory'); ?> </a></a></h1> </div> <?php echo do_shortcode('[woocommerce_checkout]', 'alterinventory'); ?> <?php } }