Site icon Hip-Hop Website Design and Development

How to update ticket price programatically when adding to cart and checkout in woocommerce

I am using events ticket plus plugin and i have created events ticket but for some reason i need to update the price of a ticket when adding to cart and checkout page.

I have used this code.

add_action( ‘woocommerce_before_calculate_totals’, ‘misha_recalculate_price’ );

function misha_recalculate_price( $cart_object ) {

if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    return;

    foreach ( $cart_object->get_cart() as $hash => $value ) {
        $pid=$value['product_id'];

                               
               
                $value['data']->set_price(10 );
                
            
        
    }


}

This code is working for all normal products (setting price to $10) but for event tickets its not working at all and price shows the same as added in the admin panel on cart and checkout. I want to change the event ticket price to my custom price (programmatically) only when adding to cart and checkout.

I have these plugins. Events tickets plugin, Events ticket plus plugin Using woocommerce.