Support

Account

Home Forums General Issues ACF and Woocomerce Surcharge

Helping

ACF and Woocomerce Surcharge

  • hi there

    i’m trying to implement a surcharge feature that goes into the woocommerce cart. the code is below, but it doesn’t seem to pickup the custom field, which is ‘surcharge’

    // Packing fee
    add_action( ‘woocommerce_cart_calculate_fees’,’wc_add_surcharge’ );
    function wc_add_surcharge( $cart ) { ?>

    <?php if(get_field(‘surcharge’) != 8) {
    $fee = 4;
    } else { $fee = 8;}

    /** Assign surcharge_fee to fee **/
    $cart->add_fee( ‘Surcharge’, $fee );
    }
    ?>

    any idea why it’s not picking up the value in ‘surcharge’?

  • Where is the field located/associated? On the product?

    If it is then you will need to supply the product ID get_field(surcharge, $product->ID);

    The question you have to answer is how do you get the product ID inside of this WC filter?

    If the field is located somewhere else then you will also need to supply the correct ID for ACF to find the field? If not on the product then where is the field?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.