Advertisement
rochekaid

Untitled

May 18th, 2024 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. // Add to cart after Gravity Form Submission
  2. add_filter('gform_confirmation', 'custom_add_cart', 10, 4);
  3. function custom_add_cart($confirmation, $form, $entry, $ajax) {
  4. if ($form['id'] == 285) { // Replace 285 with your form id
  5. $field_id = 1; // Replace with the ID of the checkbox items field
  6. $field = GFAPI::get_field($entry['form_id'], $field_id);
  7.  
  8. $selected_items = array();
  9. if ($field instanceof GF_Field_Checkbox) {
  10. $selected_items = $field->get_value_export($entry, $field_id, false);
  11. $selected_items = explode(",", $selected_items);
  12. }
  13.  
  14. $demo_id = rgar($entry, '3'); // Replace 3 with field id of demo id
  15.  
  16. $items = array();
  17. if (!empty($selected_items)) {
  18. foreach ($selected_items as $selected_item) {
  19. $items[] = $selected_item;
  20. $items[] = '1'; // 1 is the quantity
  21. }
  22. }
  23.  
  24. if (!empty($items)) {
  25. // Create the redirect URL
  26. $redirect_url = 'https://www.stampinup.com/cart?items=' . urlencode(implode(",", $items)) . '&demoid=' . urlencode($demo_id);
  27.  
  28. // Set the confirmation type to redirect
  29. $confirmation = array('redirect' => $redirect_url);
  30. }
  31. }
  32.  
  33. return $confirmation;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement