WooCommerce 添加到购物车时保存多个属性值

问题描述 投票:0回答:1

我创建了一个食物碗创建器。 http://klanten.visual.be/demoestuin/product/bowl-samenstellen/

我想用多个值保存我的属性。在“groenten”步骤中,您可以选择多种蔬菜。但是,当我将其添加到购物车时,只会保存一个变体的属性。这是符合逻辑的。

有人可以告诉我当我将此产品添加到购物车时如何将多个属性值保存到帖子对象吗?

提前谢谢您

编辑:
我找到了一个有效的示例,但我无法联系到那个人。它实际上和我想做的一样:fingerfoodaffair-shop.ch/product/sandwich。在screenshot中可以看到字符串中有多个属性。

这正是我想要的,如何将属性中的多个值保存在字符串中,例如:attribute1,attribute2,attribute3

php wordpress woocommerce attributes
1个回答
0
投票

使用 JQuery 获取所选属性 ID、当前产品 ID、数量等。 然后发送ajax请求。在您的 get ajax 请求中粘贴此代码。您的所有属性都添加到购物车中。并在 ajax 响应窗口中重定向到购物车页面。

global $wpdb;
    global $woocommerce;

    $proid =$_POST['proid'];
    $variationid =$_POST['valpj'];
    $quantity =$_POST['quantity'];
    $arr = array();
    $arr['Photos'] = 'Pics';

    foreach($variationid as $variationid1){
          //echo $variationid1. '<br  />';          
          $woocommerce->cart->add_to_cart( $proid, $quantity, $variationid1, $arr, null ); 

    }
© www.soinside.com 2019 - 2024. All rights reserved.