【问题标题】:Expand woocommerce single product page functionality with html用html扩展woocommerce单品页面功能
【发布时间】:2017-09-19 16:20:12
【问题描述】:

我知道可以通过 html 将复选框和其他内容添加到 woocommerce 单一产品描述/产品简要描述(完成)。为了保存给定的客户选择并将信息传递到购物车,是否有可能/挂钩是什么?客户可以做出选择,但遗憾的是 woocommerce 不会传递任何信息。

谢谢

【问题讨论】:

  • 你可以试试Product Addons
  • 嗨,感谢 helgatheviking 的快速回答。我考虑过使用插件,但不幸的是这是不可能的,因为插件不允许使用图像而不是复选框(我已经联系过他们)。因为编写 html 非常容易,所以我只需要知道如何链接到 woocommerce 以传递选择的信息。
  • 我选择使用 woocommerce 重力表格产品插件。谢谢

标签: woocommerce hook


【解决方案1】:

是的,您可以添加自己的 HTML,然后可以使用这些数据到购物车,这些提示对您很有用。
你可以使用一个动作

"add_filter( 'woocommerce_add_cart_item_data', 'Your_own_function', 10, 2);"

function Your_own_function($cart_data,$pro_id){
    if(isset($_POST['your_checkbox_value'])){
      $item_meta['your_meta_key'] = $_POST['your_checkbox_value'];
      $cart_data ['product_meta'] = array('meta_data' => $item_meta);
    }
    return $cart_data;
}

然后您可以使用

检索这些购物车商品数据
"add_filter( 'woocommerce_get_item_data', "custom_get_item_data", 10, 2 );"

function custom_get_item_data($item_meta, $existing_item_meta){
foreach ($existing_item_meta['product_meta'] ['meta_data'] as $key => $val )
    {
    if($key == 'your_meta_key'){

        $item_meta [] = array (
                'name' => __('Custom Name','Text Domain'),
                'value' => stripslashes( $val ),
                );
        }
    }
    return $item_meta;    
}

【讨论】:

    猜你喜欢
    • 2021-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2017-10-27
    相关资源
    最近更新 更多