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 Below is my code

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

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


////////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; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.