Advertisement
asadsuman

customloopAddtocart

Jan 2nd, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <?php
  2. /**
  3. * Loop Add to Cart
  4. */
  5.  
  6. global $product;
  7.  
  8. if( $product->get_price() === '' && $product->product_type != 'external' ) return;
  9. ?>
  10.  
  11. <?php if ( ! $product->is_in_stock() ) : ?>
  12.  
  13. <a href="<?php echo get_permalink($product->id); ?>" class="button"><?php echo apply_filters('out_of_stock_add_to_cart_text', __('Read More', 'woocommerce')); ?></a>
  14.  
  15. <?php else : ?>
  16.  
  17. <?php
  18.  
  19. switch ( $product->product_type ) {
  20. case "variable" :
  21. $link = get_permalink($product->id);
  22. $label = apply_filters('variable_add_to_cart_text', __('Select options', 'woocommerce'));
  23. break;
  24. case "grouped" :
  25. $link = get_permalink($product->id);
  26. $label = apply_filters('grouped_add_to_cart_text', __('View options', 'woocommerce'));
  27. break;
  28. case "external" :
  29. $link = get_permalink($product->id);
  30. $label = apply_filters('external_add_to_cart_text', __('Read More', 'woocommerce'));
  31. break;
  32. default :
  33. $link = esc_url( $product->add_to_cart_url() );
  34. $label = apply_filters('add_to_cart_text', __('Add to cart', 'woocommerce'));
  35. break;
  36. }
  37.  
  38. //printf('<a href="%s" rel="nofollow" data-product_id="%s" class="button add_to_cart_button product_type_%s">%s</a>', $link, $product->id, $product->product_type, $label);
  39.  
  40. if ( $product->product_type == 'simple' ) {
  41.  
  42. ?>
  43. <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>
  44.  
  45. <?php woocommerce_quantity_input(); ?>
  46.  
  47. <button type="submit" class="button alt"><?php echo $label; ?></button>
  48.  
  49. </form>
  50. <?php
  51.  
  52. } else {
  53.  
  54. printf('<a href="%s" rel="nofollow" data-product_id="%s" class="button add_to_cart_button product_type_%s">%s</a>', $link, $product->id, $product->product_type, $label);
  55.  
  56. }
  57.  
  58. ?>
  59.  
  60. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement