{% comment %} Custom Measurement Block - Updated for Product-Specific Fields & Add-ons File: blocks/custom_measurement_block.liquid {% endcomment %} {%- liquid # ================================ # 1. GET CONFIGURATION FROM METAFIELD # ================================ assign config = shop.metafields.custom_measurements.config # Initialize variables assign show_block = false assign button_text = 'Customize This Item' assign modal_title = 'Custom Measurements' assign instructions = '' assign save_button_text = 'Save & Add to Cart' if config and config.value assign full_config = config.value # Extract values safely assign button_text = full_config.button_text | default: 'Customize This Item' assign modal_title = full_config.modal_title | default: 'Custom Measurements' assign save_button_text = full_config.save_button_text | default: 'Save & Add to Cart' assign instructions = full_config.instructions | default: '' # ========================================== # Check if product is enabled at ALL # ========================================== assign is_enabled = false assign current_product_id = product.id | append: '' # Check 1: Is enabled_for_all TRUE? if full_config.enabled_for_all == true assign is_enabled = true elsif full_config.enabled_for_all == 1 assign is_enabled = true elsif full_config.enabled_for_all == '1' assign is_enabled = true endif # Check 2: If not enabled for all, check specific products unless is_enabled if full_config.enabled_products for enabled_id in full_config.enabled_products assign enabled_id_string = enabled_id | append: '' if enabled_id_string == current_product_id assign is_enabled = true break endif endfor endif endunless # Check 3: If still not enabled, check product types unless is_enabled if full_config.enabled_product_types and product.type != blank assign current_type = product.type | downcase for enabled_type in full_config.enabled_product_types assign enabled_type_lower = enabled_type | downcase if enabled_type_lower == current_type assign is_enabled = true break endif endfor endif endunless # Check 4: If product is enabled at all, we'll show the block # (individual field/product filtering happens in JavaScript) if is_enabled assign show_block = true endif endif # Override with block settings if provided if block.settings.button_text != blank assign button_text = block.settings.button_text endif # Get product price for display assign product_price = product.price | money_without_currency | remove: ',' | plus: 0 -%} {%- if show_block -%} {%- capture modal_id -%}custom-measurements-{{ section.id }}-{{ block.id }}{%- endcapture -%} {%- capture input_id -%}custom-measurements-data-{{ section.id }}-{{ block.id }}{%- endcapture -%}