Access our premium support and let us know your problems, we will help you solve them.

0
No products in the cart.

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: WooCommerce: Add product to cart with price override? #10021
    blanksumon-cse-sust
    Participant

    For the WordPress and Woocommerce latest version,Please use like this

    add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
    
    function add_custom_price( $cart_object ) {
        foreach ( $cart_object->cart_contents as $key => $value ) {
            $custom_price = 5;
            $value['data']->set_price($custom_price); 
        }
    }
    
Viewing 1 post (of 1 total)