Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setCookie(name, value, hours) {
- var expires = "";
- if (hours) {
- var date = new Date();
- date.setTime(date.getTime() + (hours*60*60*1000));
- expires = "; expires=" + date.toUTCString();
- }
- document.cookie = name + "=" + (value || "") + expires + "; path=/";
- }
- btn.onclick = function() {
- setCookie("interior", interior.currentColor, 0.1);
- }
- add_filter('woocommerce_add_cart_item_data','custom_add_item_data',10,3);
- function custom_add_item_data($cart_item_data, $product_id, $variation_id)
- {
- if($product_id == 65)
- {
- if (isset($_COOKIE['interior'])) {
- $cart_item_data['custom'] = "Interior: " + $_COOKIE["interior"];
- }
- }
- return $cart_item_data;
- }
- add_filter('woocommerce_get_item_data','custom_add_item_meta',10,2);
- function custom_add_item_meta($item_data, $cart_item)
- {
- if(array_key_exists('custom', $cart_item))
- {
- $custom_details = $cart_item['custom'];
- $item_data[] = array(
- 'key' => 'Details',
- 'value' => $custom_details
- );
- }
- return $item_data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement