Answer the question
In order to leave comments, you need to log in
How to add product to cart in Woocommerce via REST?
function wts_add_to_cart()
{
$product_id = $_GET['product_id'];
WC()->cart->add_to_cart( $product_id );
$data = [ 'name' => 'Product 1', 'product_id' => (int) $product_id ];//для теста
return $data;
}
register_rest_route('wts/v1', 'cart/add', [
'methods' => 'POST',
'callback' => 'wts_add_to_cart',
]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question