• Resolved hageshiku

    (@hageshiku)


    store_url2 = 'https://18.185.149.134/wp-json/wc/store/v1/cart/items'
    
    product = wcapi.get("products/17").json()
    
    response2= requests.get(store_url2) # CART + BU [] > 
    
    print( response2.headers.get('nonce' ))
    
    print(response2.headers.get('cart-token'))
    
    print(response2.json())
    
    headers = {
    
    'nonce': response2.headers.get('nonce'),
    
    'cart-token': response2.headers.get('cart-token'),
    
    }
    
    print(payload)# id:17 quantity:1
    
    response3 = requests.post(store_url2, json=payload, headers=headers)
    
    if response3.status_code == 200:
    
    print(response3.status_code)
    
    print("Product added successfully.")
    
    else:
    
    print(response3.status_code)
    
    print("Error while adding the product. Error message:", response3.text)
    Expand
    

    So, I have used the Requests module in Python to add products to my cart. The website is created with WordPress. It includes WooCommerce too. I included nonce and cart-token in my code. We made the product purchasable cause it was False, and we made it True. Right now, the website is not accessible. Cause we thought maybe our website must be HTTPS rather than HTTP.

    Other than that, can you please check my code to see if it’s right or wrong? I am in the dark here. I need to be able to send it to the cart.

    Lastly, I have checked my GET/POST methods.?https://18.185.149.134/wp-json/wc/store/v1/cart/items?outputs a?[ ], which is a cart empty list. I would be so grateful if someone could shine the tunnel ahead. Honestly, thanks in advance. Take care.

Viewing 1 replies (of 1 total)
  • Saif

    (@babylon1999)

    Hello @hageshiku,

    Thank you for reaching out!

    Sorry to disappoint, but we don’t offer support for custom solutions in these forums. Also, v1 of the REST API has been deprecated for quite some time.

    One possible solution you can try is using the ?add-to-cart parameter and attaching your session details.

    https://yourproducturl.com/checkout/?add-to-cart=%ID%

    If you require assistance from a developer, consider hiring a WooExpert.

    Cheers!

Viewing 1 replies (of 1 total)
  • The topic ‘WooCommerce and Rest API. Can’t Add to Cart’ is closed to new replies.