为了账号安全,请及时绑定邮箱和手机立即绑定

根据自定义字段和数量阈值更改 WooCommerce 购物车商品价格

根据自定义字段和数量阈值更改 WooCommerce 购物车商品价格

PHP
宝慕林4294392 2023-04-15 17:18:45
当购物车商品数量达到特定阈值时,我试图通过定义为产品自定义字段(产品自定义元数据)的批量价格从产品变体更改购物车商品价格。我的工作来自: WooCommerce:从产品变体中获取自定义字段并将其显示在“附加信息区域” 和WooCommerce:无需插件的批量动态定价这就是我所拥有的:add_action( 'woocommerce_before_calculate_totals', 'bbloomer_quantity_based_pricing', 9999 );function bbloomer_quantity_based_pricing( $cart, $variation_data ) {    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;    if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 ) return;    //get    $bulk_price = get_post_meta( $variation_data[ 'variation_id' ], 'bulk_price', true);    if ( $bulk_price ) {        $threshold1 = 6; // Change price if items > 6        foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {            if ( $cart_item['quantity'] >= $threshold1 ) {                $price = $bulk_price;                $cart_item['data']->set_price( $price );            }        }      }}但它不起作用,因为我无法获得批量价格的自定义字段值。
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 48 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信