wp-graphql-woocommerce icon indicating copy to clipboard operation
wp-graphql-woocommerce copied to clipboard

addToCart mutation on custom fields

Open sn3h opened this issue 4 years ago • 3 comments

Is your feature request related to a problem? Please describe. I need to let a customer add custom value to product parameters, i.e. custom text on tshirt, and/or change value of the product based on those values.. Attributes have predefined values and cannot be customized.

Describe the solution you'd like Set custom fields value using AFC(or other solution that adds custom fields to products, like Advanced Product Fields for WooCommerce).

Describe alternatives you've considered After multiple fails to achieve this with WC + wpgqlWC, I am considering only calling login mutation with some private function not to expose JWT and creating product configured by the costumer before adding it to basket, but it has many problems such as I don't know if the order will be finished and paid at the moment of adding it.

Additional context Images of what state is unreachable now, source is images taken from https://product-demo.studiowombat.com/ image image baseket : image

sn3h avatar Feb 20 '21 02:02 sn3h

@sn3h Did get a workaround for this?

jasminetracey avatar May 11 '21 02:05 jasminetracey

@jasminetracey Hi. Well there are few options, none of them perfect.

  1. You can create order with all required parameters with admin login (with some proxy that handles login), but then there's a problem with getting payment link and verifying that the order is withnin some "reasonable" boundries (anyone can send any payload unless protected with custom logic)
  2. just write / hire someone to write custom php funcitons that will do the price modifications based on meta data. You can start here https://rudrastyh.com/woocommerce/change-product-prices-in-cart.html .
addToCart(
	input: {
      productId: 47, 
      quantity: 1,
    e```
xtraData:"{\"custom_key\":\"custom_value\"}"
  })

will add line item extraData array of objects

"extraData": [
                {
                  "id": "cart___custom_key",
                  "key": "custom_key",
                  "value": "custom_value"
                },...
              ]

so you can modify the price of cart based on your extra data. You have to parse numbers as WC stores everything in extraData as string (no comment on that) .

Big difference vs #1 is that you don't even get your extraData on cart___contents___nodes to show anywhere like if you add metaData to lineItems in createOrder, so you don't see them in the order in WC UI. and have to handle it again This is absolutely terrible and again custom logic is needed.


I am forced to go with #2 but I am quite unhappy with it. So I was checking for option #3 which is another ecommerce solution, but there are some issues everywhere, so I am stuck with 2. Possitive thing about 2 is that you can use starters (gatsby and next) for the logic and save some time.

If you can handle payments yourself and don't need some WP/WC heavylifting you can try https://cartql.com/ to manage cart or try snipcart and other headless solutions.

I hope I helped at least a little

sn3h avatar May 11 '21 09:05 sn3h

Thanks for the suggestions i'll try them out and see which one works best

jasminetracey avatar May 11 '21 15:05 jasminetracey

@sn3h You should be able to your desired functionality with WooGraphQL Pro and Product Addons, otherwise your feature request is beyond the scope of WooGraphQL. I'll be closing this issue.

kidunot89 avatar Apr 20 '23 22:04 kidunot89