add_filter is not working inside IF statement. Need help please.

  • Unknown's avatar

    function custom_percetage_fee( $cart ) {
    // Only on checkout

    if ( ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) || ! is_checkout() )

    return;

    ////////add price

    if( WC()->session->get(‘enable_fee’) )

    add_filter(‘woocommerce_get_price’, ‘return_custom_price’, 10, 2);

    }

    function return_custom_price($price, $product)
    {
    global $post, $blog_id;

    $product = wc_get_product( $post_id );

    $post_id = $post->ID;

    $price = $price + ($price*0.25) ;

    return $price;
    }

    I code this to add 25% on the custom price of each product with a checkbox trigger in checkout.
    I have a problem that when I use hook ” add_filter ” inside IF statement to apply on checking it’s not working correctly but if I use this hook outside the IF statement its working fine. I search a lot but failed to achieve this. I don’t know what should I do..? Please help me.
    THANK you

  • Hi there,

    You’re in the wrong forum. To get help with the WooCommerce plugin you need to post in these forums:

    https://wordpress.org/support/plugin/woocommerce

    The forums you are currently posting are for providing support to WordPress.com hosted sites only.

  • The topic ‘add_filter is not working inside IF statement. Need help please.’ is closed to new replies.