• I am creating a plugin for Woocommerce which offers the facility to add a late fee for a course depending on the late fee date. Late fee application is working well but I want to add custom metadata to fee line item in order (like semester id, late fee date, and late fees) so that in next order for the same customer if he purchases the course from same semester he should not have to pay late fee, it is only once per semester.

    Can I append metadata to a fee line item in Woocommerce?

    I tried the following but I am getting a JSON error:

    // define the woocommerce_add_order_fee_meta callback
    function action_woocommerce_add_order_fee_meta( $order_id, $item_id, $fee, $fee_key ) {
    // make action magic happen here…
    global $woocommerce;
    $values = WC()->session;

    if ( array_key_exists( ‘late_fee_session’, $values ) )
    foreach ($values as $key=>$value) {
    if ($key == ‘late_fee_session’) {
    $cart_item_data = $value ;
    if (!empty($cart_item_data)) {
    wc_add_order_item_meta( $item_id, $fee_key, $cart_item_data );
    }
    }
    }

    };

    // add the action
    add_action( ‘woocommerce_add_order_fee_meta’, ‘action_woocommerce_add_order_fee_meta’, 10, 4 );

  • The topic ‘Can I append metadata to a fee line item in Woocommerce’ is closed to new replies.