HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/CW-techs/wp-content/themes/cw-techs/page-cart.php
<?php
/**
 * Template Name: Custom Cart Page
 */

defined('ABSPATH') || exit;
get_header();
?>

<section class="cart-page">
  <div class="container custom-container">
    
    <div class="cart-header">
      <a href="<?php echo esc_url(home_url()); ?>" class="link-text">
        <img src="<?php echo get_template_directory_uri(); ?>/img/arrow1s.svg"> Back to Home
      </a>
      <h2 class="cart-title">OUR <span>CART</span></h2>
      <div class="text-sec">
        <span><?php echo WC()->cart->get_cart_contents_count(); ?></span> items in your cart

      </div>
    </div>

    <div class="row cart-inner">
      <div class="col-md-8 cart-inner-sec">
        <?php if ( WC()->cart->is_empty() ) : ?>
            <section class="no-data">
                <div class="no-data-img">
                    <img src="<?php echo get_stylesheet_directory_uri(); ?>/img/no-data-img.svg" alt="no-data">
                </div>
                <p class="no-msg">Your cart is currently empty.</p>
            </section>
        <?php else : ?>
            <?php foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) :
                $_product = $cart_item['data'];
                $product_id = $cart_item['product_id'];

                if ( ! $_product || ! $_product->exists() ) continue;

                $product_permalink = $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '';
                $thumbnail = $_product->get_image();
                $price = WC()->cart->get_product_price( $_product );
                $qty = $cart_item['quantity'];
                $terms = get_the_terms( $product_id, 'product_brand' );
                $sale_price = $_product->get_sale_price();
                $regular_price = $_product->get_regular_price();

                // Fallback if no sale
                if ( $sale_price && $regular_price > 0 ) {
                    $discount = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );
                } else {
                    $discount = 0;
                }
            ?>
            <div class="cart-item" data-cart-item-key="<?php echo esc_attr($cart_item_key); ?>">
                <div class="product-inner">
                    <div class="product-sec">
                        <div class="product"><?php echo $thumbnail; ?></div>
                        <?php if ( ! $_product->is_in_stock() ) : ?>
                            <div class="out-of-stock">Out of Stock</div>
                        <?php endif; ?>
                    </div>
                    <div class="product-details">
                        <h5 class="product-name"><?php echo $_product->get_name(); ?></h5>
                        <div class="tags">
                             <?php if ( ($terms = get_the_terms($product_id, 'product_brand')) && !is_wp_error($terms) ) : ?>
                                  <span class="badge">
                                      <a href="<?= esc_url(get_term_link($terms[0])) ?>"><?= esc_html($terms[0]->name) ?></a>
                                  </span>
                              <?php endif; ?>
                            <span class="badge txt-sec">
                                <span><?php echo wc_price( $sale_price ?: $regular_price ); ?></span>
                                <?php if ( $sale_price && $sale_price < $regular_price ) : ?>
                                    <span class="txt"><?php echo wc_price( $regular_price ); ?></span>
                                    <span class="txt-col"><?php echo $discount; ?>%</span>
                                <?php endif; ?>
                            </span>
                            <span class="badge">Qty:&nbsp;<span class="current-qty"><?php echo intval($qty); ?></span></span>
                            <?php
                              // Product color and spec
                              $product_color = get_post_meta($product_id, 'product_color', true);
                              $product_spec = get_post_meta($product_id, 'product_specification', true);

                              if (!empty($product_color)) {
                                echo '<span class="badge">' . esc_html($product_color) . '</span>';
                              }

                              if (!empty($product_spec)) {
                                echo '<span class="badge">' . esc_html($product_spec) . '</span>';
                              }
                            ?>
                        </div>
                    </div>
                </div>

                <div class="quatity">
                    <div class="qty-box">
                        <button class="plus" title="Increase quantity">
                            <img src="<?php echo get_template_directory_uri(); ?>/img/add-symbol.svg" alt="plus">
                        </button>

                        <button class="minus" title="Decrease quantity">
                            <img src="<?php echo get_template_directory_uri(); ?>/img/minus-symbol.svg" alt="minus">
                        </button>

                        <button class="delete" title="Remove item">
                            <img src="<?php echo get_template_directory_uri(); ?>/img/delte-ico.svg" alt="delete">
                        </button>
                    </div>

                </div>
            </div>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>


      <div class="col-md-4 cart-rt-sec">
        <div class="cart-summary">
          <div class="card-details">
            <div class="total-amount-txt">Sub Total</div>
            <div class="total-amount-txt"><?php wc_cart_totals_subtotal_html(); ?></div>
          </div>
         <?php
          $packages = WC()->shipping()->get_packages();
          $has_shipping = false;

          // Check if there is a shipping total > 0
          foreach ( $packages as $package ) {
              if ( isset( $package['rates'] ) && is_array( $package['rates'] ) ) {
                  foreach ( $package['rates'] as $rate ) {
                      if ( $rate->cost > 0 ) {
                          $has_shipping = true;
                          break 2;
                      }
                  }
              }
          }

          if ( $has_shipping ) : ?>
            <div class="card-details">
              <div class="total-amount-txt">Shipping</div>
              <div class="total-amount-txt">
                <?php wc_cart_totals_shipping_html(); ?>
              </div>
            </div>
          <?php endif; ?>

          <div class="totl-sec">
            <div class="totl-amunt">Total Amount</div>
            <div class="totl-amunt"><?php wc_cart_totals_order_total_html(); ?></div>
          </div>
        </div>

        <div class="checkout-sec">
          <a href="<?php echo esc_url( wc_get_checkout_url() ); ?>" class="checkout-btn proceed-to-checkout">Proceed to checkout</a>
        </div>
      </div>
    </div>

  </div>
</section>

<div class="modal remove-modal fade" id="removeModalDelete" tabindex="-1" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">

      <div class="modal-header">
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>

      <div class="modal-body">
        <div class="icon-circle">
          <img src="<?php echo get_template_directory_uri(); ?>/img/remove-cart-icon.svg" alt="remove-cart-icon">
        </div>
        <div class="modal-title">Remove item from cart</div>
        <div class="modal-subtext">Are you sure you want to delete this<br> item from your cart?</div>
      </div>

      <div class="modal-footer">
        <input type="hidden" id="confirmRemoveKey" value="">
        <button class="btn cancel" data-bs-dismiss="modal">Cancel</button>
        <button class="btn remove-confirm remove">Remove</button>
      </div>
    </div>
  </div>
</div>
<?php get_footer(); ?>