Guest User

Untitled

a guest
Nov 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.71 KB | None | 0 0
  1. <h1> PRODUCT TABLE LIST </h1>
  2. <table>
  3.  
  4. <thead>
  5. <tr>
  6. <th></th>
  7. <th>Name</th>
  8. <th>Message</th>
  9. <th>Price</th>
  10. <th>Quantity</th>
  11. <th>Total Quantity</th>
  12. <th></th>
  13. </tr>
  14. </thead>
  15.  
  16. <tbody class="products">
  17. <?php
  18.  
  19.  
  20.  
  21. $args = array(
  22. 'post_type' => array('product', 'product_variation'),
  23. 'posts_per_page' => 5,
  24. 'product_cat' => '',
  25. 'post__in' => array( 521, 695, 852, 457, 961, 188, 399, 80, 109, 182, 108, 184, 171, 206, 197 ), // 15 products
  26. 'orderby' => 'id',
  27. 'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1 );
  28. $wp_query = new WP_Query( $args );
  29. while ( $wp_query->have_posts() ) : $wp_query->the_post(); global $product; ?>
  30.  
  31.  
  32. <?php if ( $product->is_type( 'variable' ) ) { ?>
  33. <?php show_variable_products_list(); ?>
  34. <?php
  35. }
  36. else {
  37. ?>
  38. <tr class="product-<?php echo esc_attr( $product->id ); ?>">
  39. <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>
  40. <a href="<?php echo get_permalink( $wp_query->post->ID ) ?>" title="<?php echo esc_attr($wp_query->post->post_title ? $wp_query->post->post_title : $wp_query->post->ID); ?>">
  41. <td class="image">
  42. <?php woocommerce_show_product_sale_flash( $post, $product ); ?>
  43.  
  44. <?php if (has_post_thumbnail( $wp_query->post->ID )) echo get_the_post_thumbnail($wp_query->post->ID, 'wh_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="150px" height="150px" />'; ?>
  45. </td>
  46.  
  47. <td class="title">
  48. <h3><?php the_title(); ?></h3>
  49. </td>
  50.  
  51. <td class="note">
  52. <?php wholesale_msg_note(); ?>
  53. <?php wholesale_letter_note(); ?>
  54. </td>
  55.  
  56. <td class="price">
  57.  
  58. <span class="woocommerce-Price-amount amount">
  59. <span class="woocommerce-Price-currencySymbol">
  60. <?php echo get_woocommerce_currency_symbol(); ?>
  61. </span>
  62. <?php echo $product->get_price() ?>
  63. </span>
  64. </td>
  65.  
  66. </a>
  67.  
  68. <td class="quantity-cs">
  69. <table>
  70. <tr>
  71. <?php echo wholesale_sc_note(); ?>
  72. </tr>
  73.  
  74. <tr>
  75. <?php echo wholesale_kw_note(); ?>
  76. </tr>
  77. </table>
  78.  
  79. </td>
  80.  
  81.  
  82.  
  83. <td class="quantity-total">
  84. <?php //woocommerce_quantity_input(); //This function generates the quantity field. ?>
  85. <div class="quantity">
  86. <input type="number" step="1" min="1" max="" name="quantity" value="1" title="Qty" class="input-text qty text" size="4" pattern="[0-9]*" inputmode="numeric" />
  87. </div>
  88. </td>
  89.  
  90. <td class="button">
  91.  
  92. <input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
  93. <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" />
  94. <input type="hidden" name="variation_id" class="variation_id" value="0" />
  95. <button type="submit" class="button buy-now-btn cart-btn product_type_simple add_to_cart_button ajax_add_to_cart" />Add to Cart</button>
  96.  
  97. </td>
  98.  
  99. </form>
  100.  
  101.  
  102.  
  103. <?php
  104. }
  105. ?>
  106.  
  107.  
  108.  
  109.  
  110. </tr>
  111. </tbody>
  112.  
  113. <?php endwhile; ?>
  114.  
  115. </table><!--/.products-->
  116. <div>
  117. <?php previous_posts_link( 'Older Posts' ); ?>
  118. <?php next_posts_link( 'New Posts' , $wp_query->max_num_pages ); ?>
  119. </div>
  120. <?php
  121. /*
  122. PAGINATION
  123. */
  124. if ( function_exists( 'wp_pagenavi' ) ) {
  125. ?>
  126.  
  127. <div id="pagination">
  128. <?php wp_pagenavi( array( 'query' => $wp_query ) ); ?>
  129. </div>
  130. <?php } ?>
  131. <?php wp_reset_query(); ?>
  132. ?>
  133.  
  134. function show_variable_products_list(){
  135. global $product, $post;
  136.  
  137. $variations = find_valid_variations();
  138.  
  139.  
  140. // Check if the special 'price_grid' meta is set, if it is, load the default template:
  141. if ( get_post_meta($post->ID, 'price_grid', true) ) {
  142. // Enqueue variation scripts
  143. wp_enqueue_script( 'wc-add-to-cart-variation' );
  144.  
  145. // Load the template
  146. wc_get_template( 'woocommerce/single-product/add-to-cart/variable.php', array(
  147. 'available_variations' => $product->get_available_variations(),
  148. 'attributes' => $product->get_variation_attributes(),
  149. 'selected_attributes' => $product->get_variation_default_attributes()
  150. ) );
  151. return;
  152. }
  153.  
  154. // Cool, lets do our own template!
  155. ?>
  156.  
  157.  
  158. <?php
  159. foreach ($variations as $key => $value) {
  160. if( !$value['variation_is_visible'] ) continue;
  161. ?>
  162. <tr class="product-<?php echo esc_attr( $product->id ); ?> variation-<?php echo $value['variation_id']?>">
  163. <form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->id ); ?>" data-product_variations="<?php echo htmlspecialchars( json_encode( $available_variations ) ) ?>">
  164. <td class="image">
  165. <?php echo '<img src="'.$value['image_src'].'" alt="'.$product->get_title().'-'.$value['variation_id'].'" width="150px" height="150px" />'; ?>
  166. </td>
  167. <td class="title">
  168. <h3><?php the_title(); ?></h3><br />
  169. <b><?php
  170. /*
  171. - '.get_term_by().'
  172. foreach($value['attributes'] as $key => $val ) {
  173. $val = str_replace(array('-','_'), ' ', $val);
  174. printf( '<span class="attr attr-%s">%s</span>', $key, ucwords($ival) );
  175. }
  176. */
  177.  
  178. foreach($value['attributes'] as $attr_name => $attr_value ) {
  179. $attr_name = substr($attr_name, 10);
  180. $attr = get_term_by('slug', $attr_value, $attr_name);
  181. $attr_value = $attr->name;
  182. echo $attr_value, ' ';
  183. //echo implode ('/', $attr_value );
  184. //echo $attr->name;
  185. //$attr_implode_name = implode(",", $value['attributes']);
  186.  
  187. //echo $attr_implode_name;
  188.  
  189. }
  190. ?></b>
  191. </td>
  192.  
  193. <td class="note">
  194. <?php wholesale_msg_note(); ?>
  195. <?php wholesale_letter_note(); ?>
  196. </td>
  197. <td class="price">
  198. <?php echo $value['price_html'];?>
  199. </td>
  200. <td class="keyblade">
  201. <table>
  202. <tr>
  203. <?php echo wholesale_sc_note(); ?>
  204. </tr>
  205.  
  206. <tr>
  207. <?php echo wholesale_kw_note(); ?>
  208. </tr>
  209. </table>
  210.  
  211. </td>
  212.  
  213. <?php if( $value['is_in_stock'] ) { ?>
  214.  
  215.  
  216. <td>
  217. <?php woocommerce_quantity_input(); ?>
  218. </td>
  219. <td>
  220. <?php
  221. if(!empty($value['attributes'])){
  222. foreach ($value['attributes'] as $attr_key => $attr_value) {
  223. ?>
  224. <input type="hidden" name="<?php echo $attr_key?>" value="<?php echo $attr_value?>">
  225. <?php
  226. }
  227. }
  228. ?>
  229. <button type="submit" class="single_add_to_cart_button btn btn-primary ajax_add_to_cart"><span class="glyphicon glyphicon-tag"></span> Add to cart</button>
  230. <input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
  231. <input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
  232. <input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $post->ID ); ?>" />
  233.  
  234. <?php } else { ?>
  235. <p class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
  236. <?php } ?>
  237.  
  238. </td>
  239. </form>
  240.  
  241. </tr>
  242. <?php } ?>
  243.  
  244.  
  245. <?php
  246. }
  247.  
  248.  
  249. function find_valid_variations() {
  250. global $product;
  251.  
  252. $variations = $product->get_available_variations();
  253. $attributes = $product->get_attributes();
  254. $new_variants = array();
  255.  
  256. // Loop through all variations
  257. foreach( $variations as $variation ) {
  258.  
  259. // Peruse the attributes.
  260.  
  261. // 1. If both are explicitly set, this is a valid variation
  262. // 2. If one is not set, that means any, and we must 'create' the rest.
  263.  
  264. $valid = true; // so far
  265. foreach( $attributes as $slug => $args ) {
  266. if( array_key_exists("attribute_$slug", $variation['attributes']) && !empty($variation['attributes']["attribute_$slug"]) ) {
  267. // Exists
  268.  
  269. } else {
  270. // Not exists, create
  271. $valid = false; // it contains 'anys'
  272. // loop through all options for the 'ANY' attribute, and add each
  273. foreach( explode( '|', $attributes[$slug]['value']) as $attribute ) {
  274. $attribute = trim( $attribute );
  275. $new_variant = $variation;
  276. $new_variant['attributes']["attribute_$slug"] = $attribute;
  277. $new_variants[] = $new_variant;
  278. //$woocommerce->attribute_label
  279. }
  280.  
  281. }
  282. }
  283.  
  284. // This contains ALL set attributes, and is itself a 'valid' variation.
  285. if( $valid )
  286. $new_variants[] = $variation;
  287.  
  288. }
  289.  
  290. return $new_variants;
  291. }
  292.  
  293. add_filter( 'woocommerce_variable_add_to_cart', 'show_variable_products_list', 10, 2 );
Add Comment
Please, Sign In to add comment