Add Product to Cart Programmatically
This snippet demonstrates how to add a product to the cart programmatically, which can be useful for creating custom "Add to Cart" functionality.
PHP
function add_product_to_cart( $product_id, $quantity = 1 ) {
WC()->cart->add_to_cart( $product_id, $quantity );
}
// Usage: add_product_to_cart( 123, 2 );
Snippet Feedback
Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.
SHARED BY
2 Views