WooCommerce custom Mini-Cart including a products slider with Add To Cart issues

I’m doing some customisation to the mini-cart. When a user adds a product to the cart, inside the mini-cart I’m creating a slider containing the added product’s cross-sales. So for example, user adds Product A that has cross-sales products X, Y, Z. Once his mini-cart opens he sees a slider with these products and a button to add them to the cart. The problem I’m having is that the add to cart button is not working.. I have enabled ajax add to cart and I’m noticing that only one product is getting url /?wc-ajax=add_to_cart&add-to-cart=productID, which on click just loads a white screen.. The other products in the slider have urls ?add-to-cart=productID, which on click just reloads the page and returns empty cart.. So none of the add to cart buttons is working.. In mini-cart.php, I have this code that creates the slider:

$products_cs = array();

foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {

  $the_product = wc_get_product( $cart_item['product_id'] );
  $cross_sell_ids = $the_product->get_cross_sell_ids();

  $products_cs = array_merge($products_cs, $cross_sell_ids);
  $products_cs = array_unique($products_cs);
}

<div class="mini-cart-offers">
  <button type="button" class="mini-cart-offers-prev is-disabled"></button>

  <div class="mini-cart-offers-slider">
    <?php
      foreach ( $products_cs as $offer ) :
        $offer_product = wc_get_product( $offer );
    ?>
      <div class="product-offer">
        <div class="product-offer__thumbnail">
          <?php if (has_post_thumbnail($offer_product->get_id())) : ?>
            <a href="<?php echo $offer_product->get_permalink(); ?>">
              <?php echo $offer_product->get_image($size = 'medium'); ?>
            </a>
          <?php endif; ?>
        </div>
        <div class="product-offer__content">
          <div class="product-offer__content-title">
            <a href="<?php echo $offer_product->get_permalink(); ?>">
              <h5><?php echo $offer_product->get_name(); ?></h5>
            </a>
          </div>

          <div class="product-offer__content-price">
            <?php echo $offer_product->get_price_html(); ?>
          </div>

          <div class="product-offer__content-button">
            <a href="<?php echo $offer_product->add_to_cart_url(); ?>" class="button" data-quantity="1" data-product_id="<?php echo $offer; ?>" data-product_sku="<?php echo $offer_product->get_sku(); ?>"><?php _e('Add', 'woocommerce'); ?></a>
          </div>
        </div>
      </div>
    <?php endforeach; ?>
  </div>

  <button type="button" class="mini-cart-offers-next"></button>
</div>

Also, I have this slider as a function, which is attached to woocommerce_add_to_cart_fragments:

add_filter( 'woocommerce_add_to_cart_fragments', 'cart_fragments', 10, 1 );
function cart_fragments( $fragments ) {
    if (! WC()->cart->is_empty()) {
        ob_start();
        mini_cart_slider();

        $fragments['div.widget_shopping_cart_content'] .= ob_end_clean();        
        return $fragments;
    } else {
        return $fragments;
    }
}

How to make the add to cart button work? Preferably it would be to add the product without a page refresh..

Tried hardcoding the links, but didn’t worked, tried adding different classes, but no difference..

New contributor

noob.js is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật