No Results Found
The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.
/* ---------------------------------------------- 1. Add custom fields to cart item ---------------------------------------------- */ add_filter('woocommerce_add_cart_item_data', function($cart_item_data, $product_id) { $fields = [ 'custom_price', 'custom_name', 'custom_font', 'custom_outline', 'custom_shadow', 'custom_height', 'custom_length', 'custom_colour', 'custom_bgcolour', 'custom_outline_colour', 'custom_shadow_colour', 'custom_italic', 'custom_bold' ]; foreach ($fields as $field) { if (isset($_POST[$field])) { $cart_item_data[$field] = sanitize_text_field($_POST[$field]); } } return $cart_item_data; }, 10, 2); /* ---------------------------------------------- 2. Display custom fields in cart & checkout ---------------------------------------------- */ add_filter('woocommerce_get_item_data', function($item_data, $cart_item) { $labels = [ 'custom_name' => 'Boat Name', 'custom_font' => 'Font', 'custom_outline' => 'Outline', 'custom_shadow' => 'Shadow', 'custom_height' => 'Height (cm)', 'custom_length' => 'Length (cm)', 'custom_colour' => 'Text Colour', 'custom_bgcolour' => 'Background Colour', 'custom_outline_colour' => 'Outline Colour', 'custom_shadow_colour' => 'Shadow Colour', 'custom_italic' => 'Italic', 'custom_bold' => 'Bold' ]; foreach ($labels as $key => $label) { if (!empty($cart_item[$key])) { $item_data[] = [ 'name' => $label, 'value' => $cart_item[$key] ]; } } return $item_data; }, 10, 2); /* ---------------------------------------------- 3. Save custom fields to order line items ---------------------------------------------- */ add_action('woocommerce_checkout_create_order_line_item', function($item, $cart_item_key, $values) { $fields = [ 'custom_price', 'custom_name', 'custom_font', 'custom_outline', 'custom_shadow', 'custom_height', 'custom_length', 'custom_colour', 'custom_bgcolour', 'custom_outline_colour', 'custom_shadow_colour', 'custom_italic', 'custom_bold' ]; foreach ($fields as $field) { if (isset($values[$field])) { $item->add_meta_data($field, $values[$field]); } } }, 10, 3);
The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.