How can I add a private item from my store to the cart?
$product_id = 1234;
WC()->cart->add_to_cart($product_id);
Whenever I try to do this, the item is not being added (unless I make it public). I don't want to make it public however since I want to keep these items hidden.
I have found this example after doing a search, but it doesn't explain how to actually implement it. How to display/allow 'add to cart' for private products in Woocommerce
Solution
Redirect to the WooCommerce 'shop' page if the product is viewed directly