簡體   English   中英

加入購物車

[英]Add to cart in woocommerce

我正在嘗試在圖像上執行添加到購物車功能,該圖像是購物車頁面的鏈接。 我寫了下面的代碼

simple.php

<form class="cart" method="post" onSubmit="return validateIn('<?= $product->id?>');" enctype='multipart/form-data'>
    <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>

    <?php
        if ( ! $product->is_sold_individually() )
            woocommerce_quantity_input( array(
                'min_value' => apply_filters( 'woocommerce_quantity_input_min', 1, $product ),
                'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product )
            ) );
    ?>

我在添加到購物車上做了一個動畫,之后我試圖添加添加到購物車的代碼

function validateIn(p_id){

//code for animation
event.preventDefault();
    addToCart(p_id);
  return false;




}
function addToCart(p_id) {
        jQuery.ajax({
          type: 'POST',

          url: 'addtocart.php',

          data: { 'product_id':  p_id,
          },
          success: function(response, textStatus, jqXHR){


            console.log("Product added");
            }
        }); 
  }

有人可以告訴我如何進行嗎!

在php頁面ajax url頁面中,

global $woocommerce; $woocommerce->cart->add_to_cart($product_id);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM