• I am able to add my product to the cart just fine, but I want to set the fields at the same time. I would think this is the solution: (assumed is one item in the cart, I am trying to set the “Name” field with the id 69f650596a3b4)

                            //now add product fields

                            foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {

                                $woocommerce->cart->cart_contents[ $cart_item_key ][’69f650596a3b4′] = “testing”;

    }

    I have also tried the normal names of the fields (“Name”, “Address”, etc) instead of the ID

    thanks

                     

Viewing 1 replies (of 1 total)
  • Hi @yourgarage,

    The field values cannot be added directly to the cart item like this:

    $woocommerce->cart->cart_contents[ $cart_item_key ][’69f650596a3b4′] = “testing”;

    Our plugin processes and stores field values through the woocommerce_add_cart_item_data hook and reads the values from the submitted $_POST data.

    The values are then saved inside:
    alg_wc_pif_local
    alg_wc_pif_global

    So if you are adding products programmatically, you will need to either:

    1. Submit the Product Input Fields values through $_POST before calling add_to_cart()
      or
    2. Build the same cart item data structure and pass it through the woocommerce_add_cart_item_data filter.

    Directly setting custom keys on $woocommerce->cart->cart_contents will not populate the Product Input Fields automatically.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.