Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. function setCookie(name, value, hours) {
  2. var expires = "";
  3. if (hours) {
  4. var date = new Date();
  5. date.setTime(date.getTime() + (hours*60*60*1000));
  6. expires = "; expires=" + date.toUTCString();
  7. }
  8. document.cookie = name + "=" + (value || "") + expires + "; path=/";
  9. }
  10.  
  11. btn.onclick = function() {
  12. setCookie("interior", interior.currentColor, 0.1);
  13. }
  14.  
  15. add_filter('woocommerce_add_cart_item_data','custom_add_item_data',10,3);
  16.  
  17. function custom_add_item_data($cart_item_data, $product_id, $variation_id)
  18. {
  19. if($product_id == 65)
  20. {
  21. if (isset($_COOKIE['interior'])) {
  22. $cart_item_data['custom'] = "Interior: " + $_COOKIE["interior"];
  23. }
  24. }
  25.  
  26. return $cart_item_data;
  27. }
  28.  
  29. add_filter('woocommerce_get_item_data','custom_add_item_meta',10,2);
  30. function custom_add_item_meta($item_data, $cart_item)
  31. {
  32. if(array_key_exists('custom', $cart_item))
  33. {
  34. $custom_details = $cart_item['custom'];
  35.  
  36. $item_data[] = array(
  37. 'key' => 'Details',
  38. 'value' => $custom_details
  39. );
  40. }
  41.  
  42. return $item_data;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement