• Resolved leoleq

    (@leoleq)


    Hello
    There is a plugin installed on my site that adds the ability to select paid add-ons to the product. When creating an order through the site, everything works fine, when I receive the same order through the REST API, I also see these additions in the product metadata, and the price of the product changes depending on the selected additions. But if I try to add an order via the REST API, even specifying additions in meta_data, wc does not take them into account and displays the usual price of the product.
    How can I add add-ons so that the price changes?
    P.S. I also tried to create a product first and then update it by adding add-ons, but it didn’t help

Viewing 8 replies - 1 through 8 (of 8 total)
  • Mirko P.

    (@rainfallnixfig)

    Hi @leoleq!

    Just so that it can be useful and for reference on this thread here are REST API order properties:

    https://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties

    Could you give us a bit more information and tell us what request you’re sending via REST API to create a new order in WooCommerce and how you intend to add additional charges to the price?

    Thanks.

    Thread Starter leoleq

    (@leoleq)

    @rainfallnixfig, Unfortunately, I do not have access to a computer right now, I will give more information during the day. Thanks.

    • This reply was modified 2 years, 7 months ago by leoleq.
    • This reply was modified 2 years, 7 months ago by leoleq.
    Thread Starter leoleq

    (@leoleq)

    @rainfallnixfig, Here is an example: The cost of pizza on the site is $ 4, if the user chooses an add-on worth $ 1 and places an order, then when I receive the order data, the cost of this pizza is $ 5. In the server’s response, the properties “price”, “total”, “subtotal” in the product object have the value “$5”. That is, the additions seem to change the original price, and do not impose it on top. All plug-ins of add-ons work on the same principle, I tried. I also see add-on objects in the server’s response, in the meta_data property of the product, but without a price. I tried specifying extensions in meta_data when creating an order, but it doesn’t help. Woo counts only the number and variations of the product, as described in the documentation. I believe that it is impossible to do without creating your own endpoint in the API that will place an order the way I need it. I will be glad to have any thoughts on this. Thanks.

    Mirko P.

    (@rainfallnixfig)

    Hi @leoleq,

    Thanks for sharing additional information.

    It sounds like a development topic and I’ve found this Stack Overflow thread that might address your inquiry and put you in the right direction.

    https://stackoverflow.com/a/42825007

    I’m going to leave this thread open for a bit to see if anyone else wants to chime in to help you out.

    You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack.

    We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers.

    Thread Starter leoleq

    (@leoleq)

    @rainfallnixfig, Thank you so much for your help! I would be glad if this topic remained open for a week, because I will look for a solution and if I find it, I will definitely write about it here.

    Hey @leoleq,

    You can pass a custom price for any product that’s in an order created via the REST API. In the line_items section, you could include the price. This will be the total price of the product.

    
    "line_items": [
        {
          "product_id": 1128,
          "quantity": 1,
          "subtotal": "25.00",
          "total": "25.00"
        }
      ],
    

    You’re welcome to use any of the attributes for orders that aren’t read-only when creating an order.

    You might need to adjust the request that’s sent to the REST API to account for these add-ons but it should be possible to create an order with whatever you want to charge for these products.

    https://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties

    Thread Starter leoleq

    (@leoleq)

    @3sonsdevelopment, You won’t believe it, but I just found this solution and came here to write about it. This is exactly the same as you described =) Thank you so much for your help, I think the problem is solved, the topic can be considered closed.

    Mirko P.

    (@rainfallnixfig)

    Glad to hear it – thanks for letting us know!
    
    I’ll mark this thread as resolved now. If you have any further questions, I recommend creating a new thread.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WooCommerce rest api. Accounting for additions in the final price when adding an’ is closed to new replies.