Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add to cart after Gravity Form Submission
- add_filter('gform_confirmation', 'custom_add_cart', 10, 4);
- function custom_add_cart($confirmation, $form, $entry, $ajax) {
- if ($form['id'] == 285) { // Replace 285 with your form id
- $field_id = 1; // Replace with the ID of the checkbox items field
- $field = GFAPI::get_field($entry['form_id'], $field_id);
- $selected_items = array();
- if ($field instanceof GF_Field_Checkbox) {
- $selected_items = $field->get_value_export($entry, $field_id, false);
- $selected_items = explode(",", $selected_items);
- }
- $demo_id = rgar($entry, '3'); // Replace 3 with field id of demo id
- $items = array();
- if (!empty($selected_items)) {
- foreach ($selected_items as $selected_item) {
- $items[] = $selected_item;
- $items[] = '1'; // 1 is the quantity
- }
- }
- if (!empty($items)) {
- // Create the redirect URL
- $redirect_url = 'https://www.stampinup.com/cart?items=' . urlencode(implode(",", $items)) . '&demoid=' . urlencode($demo_id);
- // Set the confirmation type to redirect
- $confirmation = array('redirect' => $redirect_url);
- }
- }
- return $confirmation;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement