single-product-price-table.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. if (!defined('WPINC')) {
  3. die;
  4. }
  5. /** @var array<int,array{id:int,label:string,base_price:float,tiers:array,in_stock:bool}> $variants */
  6. ?>
  7. <div class="studiou-fpp-price-table-wrap">
  8. <h3 class="studiou-fpp-price-table-title"><?php esc_html_e('Price list', 'studiou-wc-free-photo-product'); ?></h3>
  9. <table class="studiou-fpp-price-table">
  10. <thead>
  11. <tr>
  12. <th class="studiou-fpp-price-table-variant"><?php esc_html_e('Variant', 'studiou-wc-free-photo-product'); ?></th>
  13. <th class="studiou-fpp-price-table-price"><?php esc_html_e('Unit price', 'studiou-wc-free-photo-product'); ?></th>
  14. <th class="studiou-fpp-price-table-discount"><?php esc_html_e('Quantity discount', 'studiou-wc-free-photo-product'); ?></th>
  15. </tr>
  16. </thead>
  17. <tbody>
  18. <?php foreach ($variants as $v) :
  19. $row_classes = array('studiou-fpp-price-table-row');
  20. if (empty($v['in_stock'])) {
  21. $row_classes[] = 'studiou-fpp-price-table-row-oos';
  22. }
  23. ?>
  24. <tr class="<?php echo esc_attr(implode(' ', $row_classes)); ?>">
  25. <td class="studiou-fpp-price-table-variant"><?php echo esc_html($v['label']); ?></td>
  26. <td class="studiou-fpp-price-table-price"><?php echo wp_kses_post(wc_price($v['base_price'])); ?></td>
  27. <td class="studiou-fpp-price-table-discount">
  28. <?php if (!empty($v['tiers'])) : ?>
  29. <ul class="studiou-fpp-price-table-tiers">
  30. <?php foreach ($v['tiers'] as $tier) :
  31. $from = isset($tier['from_qty']) ? (int) $tier['from_qty'] : 0;
  32. $pct = isset($tier['percent']) ? (float) $tier['percent'] : 0.0;
  33. if ($from <= 0 || $pct <= 0) continue;
  34. $pct_str = rtrim(rtrim(number_format($pct, 2, '.', ''), '0'), '.');
  35. ?>
  36. <li class="studiou-fpp-price-table-tier">
  37. <span class="studiou-fpp-price-table-tier-qty"><?php echo esc_html($from); ?>+</span>
  38. <span class="studiou-fpp-price-table-tier-pct">&minus;<?php echo esc_html($pct_str); ?>&nbsp;%</span>
  39. </li>
  40. <?php endforeach; ?>
  41. </ul>
  42. <?php else : ?>
  43. <span class="studiou-fpp-price-table-no-discount">&mdash;</span>
  44. <?php endif; ?>
  45. </td>
  46. </tr>
  47. <?php endforeach; ?>
  48. </tbody>
  49. </table>
  50. </div>