相关疑难解决方法(0)

使用AJAX - WooCommerce API将变体添加到购物车?

我有一个包含以下数据的项目:

var item = {
  id : "124",
  name : "xxx",
  price : "13.13",
  quantity : 1,
  options : {
    "size" : "xl",
    "color": "pink"
  }
};
Run Code Online (Sandbox Code Playgroud)

当用户点击"添加到购物车"时,我想使用WC API制作Ajax请求,并将上述项目添加到购物车.

jQuery.ajax({
   url: "some/woocommerce/api/add/to/cart/request/path",
   data: item,
   type: "POST"
});
Run Code Online (Sandbox Code Playgroud)

然后在购物车页面上,我想使用WC API制作另一个Ajax请求并检索购物车的内容.

我没有找到任何关于如何使用Javascript从客户端执行此操作的文档(官方或非官方).

有谁知道并且能为我提供一个例子吗?

此外,有谁知道为什么WooCommerce Api文档是如此可怕(缺乏有关如上所述的明显/标准问题的任何信息).我正在认真考虑让我们公司改用Shopify.

javascript ajax woocommerce

11
推荐指数
2
解决办法
2万
查看次数

WooCommerce变化作为单选按钮

在WooCommerce中是否可以将变体下拉列表更改为单选按钮,而无需使用插件?我想在变体部分中进行以下设置:

  • 1升(10€)
  • 2公升(20€)
  • 3升(25€)

选择一个选项时,底部的价格应自动更改。

谢谢

wordpress woocommerce woothemes

6
推荐指数
2
解决办法
1万
查看次数

WooCommerce 3 中产品变化的 Ajax 添加到购物车按钮

我这里有这个按钮。此按钮的用途是将产品 id 为 237、变体 id 为 208673、attribute_pa_option 为蓝牙的产品添加到购物车。有没有办法 AJAX 这个?

<div class="btnss">
    <span class="price">
        <span class="woocommerce-Price-amount amount">6,999&nbsp;
            <span class="woocommerce-Price-currencySymbol">kr</span>
        </span>
    </span>
    <div class="quantity buttons_added">
        <input type="button" value="-" class="minus">
        <label class="screen-reader-text" for="quantity_5b101f605f067">Quantity</label>
        <input type="number" id="quantity_5b101f605f067" class="input-text qty text" step="1" min="1" max="" name="quantity" value="1" title="Qty" size="4" pattern="[0-9]*" inputmode="numeric" aria-labelledby="">
        <input type="button" value="+" class="plus">
    </div>
    <a href="/?add-to-cart=237&variation_id=208673&attribute_pa_option=bluetooth" class="button product_type_simple add_to_cart_button ajax_add_to_cart">Add to cart</a>
</div>
Run Code Online (Sandbox Code Playgroud)

php ajax wordpress jquery woocommerce

6
推荐指数
1
解决办法
9245
查看次数

变量产品属性:自定义每个显示的单选按钮文本值

在WooCommerce中,我使用WC Variations Radio Buttons插件(由8manos)来替换具有Radio Buttons的典型下拉选择器.

我已将以下代码添加到我的子主题中function.php:

// Display the product variation price inside the variations dropdown.
add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' );

function display_price_in_variation_option_name( $term ) {
    global $wpdb, $product;

    if ( empty( $term ) ) return $term;
    if ( empty( $product->id ) ) return $term;

    $result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" );

    $term_slug = ( !empty( $result ) ) ? $result[0] : $term;

    $query = "SELECT postmeta.post_id AS …
Run Code Online (Sandbox Code Playgroud)

php wordpress product variations woocommerce

5
推荐指数
1
解决办法
1489
查看次数

Ajax 添加到购物车,用于 WooCommerce 单品上的简单和可变产品

下面的代码适用于使用 WooCommerce 将简单产品添加到购物车,但不适用于可变产品。有人可以帮我吗?因为这个代码适用于最新的 WC,请不要删除这个问题,因为网上有很多代码根本不起作用。

我收到的错误是在通知中说我应该选择一个产品选项,即使我选择了一个。

JS:

jQuery(function($) {
        $('form.cart').on('submit', function(e) {
            e.preventDefault();

            var form = $(this);
            form.block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } });

            var formData = new FormData(form.context);
            formData.append('add-to-cart', form.find('[name=add-to-cart]').val() );

    var $thisbutton = form.find('.single_add_to_cart_button'); //


            // Ajax action
            $.ajax({
                url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'ace_add_to_cart' ),
                data: formData,
                type: 'POST',
                processData: false,
                contentType: false,
      beforeSend: function (response) {
           $thisbutton.removeClass('added').addClass('loading');
       },
                complete: function( response ) {
                    response = response.responseJSON;

                    if ( ! response ) {
                        return;
                    }

                    if …
Run Code Online (Sandbox Code Playgroud)

php ajax wordpress jquery woocommerce

2
推荐指数
1
解决办法
1244
查看次数