• Resolved deeveedee

    (@deeveedee)


    We have a custom product page that uses WooCommerce add-to-cart to pass product data to the WooCommerce shopping cart. The query string can be long. Is there a way to pass data to the WooCommerce cart via $_POST instead of via $_GET?

    This is important to us for two reasons:

    • We would feel more secure with $_POST (our product data isn’t exposed in the query string)
    • Sucuri Firewall which is active on our site occasssionally misinterprets long query strings as XSS (Cross Site Scripting) attempts and block add-to-cart.

    Thank you.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Hi there,

    Just to make sure, are you using an add-to-cart shortcode or are you referring to the default add-to-cart buttons that are rendered on the shop page? I’m asking as the latter is already submitted using $_POST:


    Link to image: https://d.pr/i/HEmZWQ

    If it’s the former, as far as I’m aware only $_GET is supported at this stage.

    Thread Starter deeveedee

    (@deeveedee)

    @riaanknoetze – thank you for your quick response. We are invoking WooCommerce add-to-cart from PHP (/cart/?add-to-cart). We populate the add-to-cart query string with our custom product parameters. This is problematic for us, because the Sucuri firewall occasionally misinterprets the long add-to-cart query string as XSS (Cross Site Scripting) and blocks the transaction (preventing the user from adding their order to the cart).

    We’re hoping that WooCommerce offers another mechanism that permits us to invoke /cart/?add-to-cart without passing custom product parameters via query string.

    Thank you.

    Thread Starter deeveedee

    (@deeveedee)

    I’m going to ask what is probably a dumb question, but I’ll ask anyway. If WooCommerce default add-to-cart buttons use $_POST to pass product data to cart, shouldn’t I be able to create my own custom add-to-cart buttons that use $_POST to pass product data to cart?

    I have highly customized product configurations produced by the customer when they design their product on my custom product design page. The product design page has an “Add To Cart” button that currently invokes /cart/?add-to-cart with a query string that specifies the custom product attributes.

    Does WooCommerce offer support for a custom “Add To Cart” button that passes data to the cart via $_POST?

    Plugin Support Senff

    (@senff)

    Hey @deeveedee

    Technically, you should be able to create your own custom add to cart buttons; WooCommerce is highly customizable that way, and you can use your own custom code in many ways.

    WooCommerce.com Support doesn’t specifically provide support for custom solutions, but that’s why we have these forums, so that you can ask other developers for advice.

    Or, if that doesn’t help and no one is able to help you here, you can always look into hiring a developer from the Customizations page on WooCommerce.com.

    Thread Starter deeveedee

    (@deeveedee)

    I think that I’m over complicating this. Could it be that if I want to insert something into the WooCommerce Shopping Cart with PHP, that I simply call function

    WC()->cart->add_to_cart()?

    • This reply was modified 3 years, 11 months ago by deeveedee.
    Thread Starter deeveedee

    (@deeveedee)

    This can now be marked SOLVED.

    Now that I understand more about the problem and solution, I would have worded my question to ask: what’s the best way to programatically submit a new product item from PHP to the WooCommerce Shopping Cart.

    The answer is: WC()->cart->add_to_cart().

    We designed our custom product page / WooCommerce interface when we were first learning WordPress and WooCommerce. It’s unfortunate that we stumbled upon the WooCommerce /cart/add-to-cart URL/query string API before we found the WC()->cart->add_to_cart() api.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Does WooCommerce add-to-cart support $_POST?’ is closed to new replies.