WooCommerce add_to_cart

The question: Is there a newer way to add product(s) to the cart?

Well, WC_Cart::add_to_cart() is still the way to do it.

Except (on the front-end), there’s no need to reinstantiate the cart class:

$cart = new WC_Cart();

because the main WooCommerce class already instantiates WC_Cart, and you can easily access the class instance like so:

$cart = wc()->cart;
//$cart = WC()->cart; // same as above, but wc() (i.e. lowercase) is actually preferred :)

where wc() is a wrapper function that returns the main instance of the main WooCommerce class.

And to add a product into the cart, you can use either of these options:

// Option #1
wc()->cart->add_to_cart( $product_id );

// Option #2: Here we assign wc()->cart to a variable.
$cart = wc()->cart;
$cart->add_to_cart( $product_id );

Hope that helps! 🙂