donglu1973 2015-10-09 00:20 采纳率: 100%
浏览 75

WooCommerce将费用添加到woocommerce_cart_item_subtotal

I am trying to add a fee I have set up using Gravity Forms Product Add Ons. The fee comes through in the product variations, but I'm having issues trying to:

  1. Pull in within a filter
  2. Adding the fee only once to the subtotal in the cart row.

Here is what I have so far:

// define the woocommerce_cart_item_subtotal callback
function filter_woocommerce_cart_item_subtotal(
        $product, $cart_item, $cart_item_key) {
    global $woocommerce;

    // 1. Find out if Setup fee is added
    $custom_setup_fee = get_post_meta($product->ID, 'value', true);
    echo $custom_setup_fee;

    /*
    echo WC()->cart->get_product_subtotal(
        $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key;
    echo WC()->cart->get_product_subtotal(
        $_product, $cart_item['quantity'] );
    */

    // 2. If setup fee added, add to existing value

    // 3. If no setup fee just return value
    return $product;
};

// add the filter
add_filter(
    'woocommerce_cart_item_subtotal', 
    'filter_woocommerce_cart_item_subtotal', 10, 3);

The first variable called $custom_setup_fee does not pull in anything. Any ideas?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化