PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/adegamalbec/woocommerce/content-product.php

https://bitbucket.org/hcdesenvolvimentos/adegamalbec_loja
PHP | 292 lines | 190 code | 49 blank | 53 comment | 45 complexity | f80a0314b4b32397b8b4ffcae6524f36 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, MIT, LGPL-2.1
  1. <?php
  2. /**
  3. * The template for displaying product content within loops
  4. *
  5. * This template can be overridden by copying it to yourtheme/woocommerce/content-product.php.
  6. *
  7. * HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
  8. * will need to copy the new files to your theme to maintain compatibility. We try to do this.
  9. * as little as possible, but it does happen. When this occurs the version of the template file will.
  10. * be bumped and the readme will list any important changes.
  11. *
  12. * @see http://docs.woothemes.com/document/template-structure/
  13. * @author WooThemes
  14. * @package WooCommerce/Templates
  15. * @version 2.5.0
  16. */
  17. global $product;
  18. //var_dump($product);
  19. if ( ! defined( 'ABSPATH' ) ) {
  20. exit; // Exit if accessed directly
  21. }
  22. global $product, $woocommerce_loop;
  23. // Store loop count we're currently on
  24. if ( empty( $woocommerce_loop['loop'] ) ) {
  25. $woocommerce_loop['loop'] = 0;
  26. }
  27. // Store column count for displaying the grid
  28. if ( empty( $woocommerce_loop['columns'] ) ) {
  29. $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 );
  30. }
  31. // Ensure visibility
  32. if ( ! $product || ! $product->is_visible() ) {
  33. return;
  34. }
  35. // Increase loop count
  36. $woocommerce_loop['loop']++;
  37. // Extra post classes
  38. $classes = array();
  39. if ( 0 === ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 === $woocommerce_loop['columns'] ) {
  40. $classes[] = 'first';
  41. }
  42. if ( 0 === $woocommerce_loop['loop'] % $woocommerce_loop['columns'] ) {
  43. $classes[] = 'last';
  44. }
  45. ?>
  46. <li class="item lista-grade" <?php post_class( $classes ); ?>>
  47. <a href="<?php the_permalink(); ?>">
  48. <div class="foto-produto">
  49. <!-- DESCONTO PORCENTAGEM -->
  50. <?php
  51. $product->get_price_html();
  52. $precoatual = $product->price;
  53. // $precoantigo = $product->regular_price;
  54. $valor = explode(";", $product->get_price_html());
  55. $precoantigo = $valor[2];
  56. $desconto = 0;
  57. if ($precoantigo != 0)
  58. $desconto = (($precoatual * 100) / $precoantigo) - 100;
  59. if ($product->is_on_sale() == "true") {
  60. # code...
  61. ?>
  62. <span class="desconto-porcetagem"><?php echo intval($desconto); ?>%</span>
  63. <?php }; ?>
  64. <?php
  65. /**
  66. * woocommerce_before_shop_loop_item hook.
  67. *
  68. * @hooked woocommerce_template_loop_product_link_open - 10
  69. */
  70. //do_action( 'woocommerce_before_shop_loop_item' );
  71. /**
  72. * woocommerce_before_shop_loop_item_title hook.
  73. *
  74. * @hooked woocommerce_show_product_loop_sale_flash - 10
  75. * @hooked woocommerce_template_loop_product_thumbnail - 10
  76. */
  77. do_action( 'woocommerce_before_shop_loop_item_title' );
  78. ?>
  79. <!-- <button class="comprar"><img src="<?php bloginfo('template_directory'); ?>/img/sacola.png" alt="">Adicionar ao carrinho</button>
  80. <?php do_action( 'woocommerce_after_shop_loop_item' ); ?> -->
  81. <?php
  82. if($product->product_type == "variable"){
  83. $prodVars = $product->get_available_variations();
  84. $urlBlog = get_template_directory_uri();
  85. foreach ($prodVars as $prodVar) {
  86. if ($prodVar["is_in_stock"] == true && $prodVar["attributes"]["attribute_pa_quantidade"] == "unidade") {
  87. $unId = $prodVar['variation_id'];
  88. echo '<a class="buy areaImgComprar link-botao-comprar" href="#" data-unId="'.$unId.'"><img src="'.$urlBlog.'/img/sacola.png" alt="icone Sacola de compras" id="sacolaCompras">Adicionar ao carrinho</a>';
  89. }
  90. }
  91. }else{
  92. $unId = $product->id;
  93. $urlBlog = get_template_directory_uri();
  94. if ($product->is_in_stock() == true && $product->get_stock_quantity() > 0) {
  95. echo '<a class="buy areaImgComprar link-botao-comprar" href="#" data-unId="'.$unId.'"><img src="'.$urlBlog.'/img/sacola.png" alt="icone Sacola de compras" id="sacolaCompras">Adicionar ao carrinho</a>';
  96. }
  97. }
  98. ?>
  99. </div>
  100. </a>
  101. <div class="conteudo">
  102. <div class="descricao-produto">
  103. <?php
  104. /**
  105. * woocommerce_shop_loop_item_title hook.
  106. *
  107. * @hooked woocommerce_template_loop_product_title - 10
  108. */
  109. do_action( 'woocommerce_shop_loop_item_title' );
  110. ?>
  111. </div>
  112. <!-- PREÇO -->
  113. <p class="preco">R$ <?php echo number_format((float)$product->get_price(),2, ',', '.'); ?></p>
  114. <?php
  115. $price = $product->get_price();
  116. $price3x = $price / 3;
  117. $price2x = $price / 2;
  118. ?>
  119. <?php if ($price >= 120): ?>
  120. <p class="promocao"><span>ou</span>3X <?php echo number_format($price3x,2,",","." ); ?></p>
  121. <?php elseif($price >= 80): ?>
  122. <p class="promocao"><span>ou</span>2X <?php echo number_format($price2x,2,",","." ); ?></p>
  123. <?php else: ?>
  124. <p class="promocao" style="height: 20px;"></p>
  125. <?php endif; ?>
  126. <div class="estrela">
  127. <?php
  128. $average = $product->get_average_rating();
  129. $avaliacao = explode(".", $average);
  130. if ($avaliacao[0] == "5") {
  131. echo'
  132. <i class="fa fa-star" aria-hidden="true"></i>
  133. <i class="fa fa-star" aria-hidden="true"></i>
  134. <i class="fa fa-star" aria-hidden="true"></i>
  135. <i class="fa fa-star" aria-hidden="true"></i>
  136. <i class="fa fa-star" aria-hidden="true"></i>
  137. ';
  138. }elseif ($avaliacao[0] == "4") {
  139. echo'
  140. <i class="fa fa-star" aria-hidden="true"></i>
  141. <i class="fa fa-star" aria-hidden="true"></i>
  142. <i class="fa fa-star" aria-hidden="true"></i>
  143. <i class="fa fa-star" aria-hidden="true"></i>
  144. <i class="fa fa-star-o" aria-hidden="true"></i>
  145. ';
  146. }elseif ($avaliacao[0] == "3") {
  147. echo'
  148. <i class="fa fa-star" aria-hidden="true"></i>
  149. <i class="fa fa-star" aria-hidden="true"></i>
  150. <i class="fa fa-star" aria-hidden="true"></i>
  151. <i class="fa fa-star-o" aria-hidden="true"></i>
  152. <i class="fa fa-star-o" aria-hidden="true"></i>
  153. ';
  154. }elseif ($avaliacao[0] == "2") {
  155. echo'
  156. <i class="fa fa-star" aria-hidden="true"></i>
  157. <i class="fa fa-star" aria-hidden="true"></i>
  158. <i class="fa fa-star" aria-hidden="true"></i>
  159. <i class="fa fa-star-o" aria-hidden="true"></i>
  160. <i class="fa fa-star-o" aria-hidden="true"></i>
  161. ';
  162. }elseif ($avaliacao[0] == "1") {
  163. echo'
  164. <i class="fa fa-star" aria-hidden="true"></i>
  165. <i class="fa fa-star" aria-hidden="true"></i>
  166. <i class="fa fa-star" aria-hidden="true"></i>
  167. <i class="fa fa-star" aria-hidden="true"></i>
  168. <i class="fa fa-star-o" aria-hidden="true"></i>
  169. ';
  170. }elseif ($avaliacao[0] == "0") {
  171. echo'
  172. <i class="fa fa-star-o" aria-hidden="true"></i>
  173. <i class="fa fa-star-o" aria-hidden="true"></i>
  174. <i class="fa fa-star-o" aria-hidden="true"></i>
  175. <i class="fa fa-star-o" aria-hidden="true"></i>
  176. <i class="fa fa-star-o" aria-hidden="true"></i>
  177. ';
  178. }
  179. ?>
  180. </div>
  181. <div class="descricao-completa">
  182. <p><?php
  183. $textoresumido = $product->post->post_content;
  184. $textocurto = substr($textoresumido, 0, 500).'...';
  185. echo $textocurto;
  186. ?></p>
  187. </div>
  188. <?php
  189. if($product->product_type == "variable"){
  190. $prodVars = $product->get_available_variations();
  191. $result = woocommerce_get_product_terms($product->id, 'pa_quantidade', 'names');
  192. foreach ($prodVars as $prodVar) {
  193. if ($prodVar["is_in_stock"] == true && $prodVar["attributes"]["attribute_pa_quantidade"] != "unidade") {
  194. $sixId = $prodVar['variation_id'];
  195. foreach ($result as $result) {
  196. $variacao = $result;
  197. if ($variacao != "Unidade") {
  198. $quantidadeCaixa = $variacao;
  199. }else{
  200. $unidade = $variacao;
  201. }
  202. }
  203. $str = $quantidadeCaixa;
  204. $qTD = filter_var($str, FILTER_SANITIZE_NUMBER_INT);
  205. $sixDiv = $prodVar['display_price'] / $qTD;
  206. $sixDiv = money_format('%.2n', $sixDiv);
  207. echo '<a class="buy6 adicionar-aocarrinho" href="#" data-sixId="'.$sixId.'">compre <b>'.$qTD.'un</b> pague <b>R$'.$sixDiv.'</b>/un</a>';
  208. } else if($prodVar["is_in_stock"] == false && $prodVar["attributes"]["attribute_pa_quantidade"] == "unidade") {
  209. echo '<p class="esgotado text-center"><i class="fa fa-times"></i> Esgotado</p>';
  210. }
  211. }
  212. }else{
  213. $quantidadeProduto = $product->get_stock_quantity();
  214. if ($quantidadeProduto = 0 || $quantidadeProduto == null) {
  215. echo '<p class="esgotado text-center"><i class="fa fa-times"></i> Esgotado</p>';
  216. }
  217. }
  218. ?>
  219. </div>
  220. <?php
  221. /**
  222. * woocommerce_after_shop_loop_item_title hook.
  223. *
  224. * @hooked woocommerce_template_loop_rating - 5
  225. * @hooked woocommerce_template_loop_price - 10
  226. */
  227. //do_action( 'woocommerce_after_shop_loop_item_title' );
  228. /**
  229. * woocommerce_after_shop_loop_item hook.
  230. *
  231. * @hooked woocommerce_template_loop_product_link_close - 5
  232. * @hooked woocommerce_template_loop_add_to_cart - 10
  233. */
  234. ?>
  235. </li>