dongzong3053 2019-03-14 12:15
浏览 61

在Woocommerce中将产品下拉列表选定值添加为购物车项目元数据

Based on "Add dropdown to products and display the value on Woocommerce cart" answer code, I'm trying to add an attribute value from a dropdown to the cart item meta data, but I don't know yet how.

<select id ="id_dropdown_one_end" name="dropdown_one_end">
    <option value_one_end="0">Ingenting</option>
    <option value_one_end="250">Øye       250,-</option>
    <option value_one_end="350">Sjakkel   350,-</option>
    <option value_one_end="400">Spleis    400,-</option>
</select>

If value_one_end attribute was named just value instead (as by default), I could get the selected value with PHP using:

$cart_item_data['price_one_end'] = esc_attr($_POST['dropdown_one_end']);

But by not having a value attribute the above statement gets the name of the option instead ('Ingenting'), which is what I want.

But how do I use php to get an attribute called something else than value? I have tried something like this:

$cart_item_data['price_one_end'] = esc_attr($_POST['dropdown_one_end'].attr('value_one_end'));

But it doesn't work.

Any ideas?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line