Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @steveneray,

    We still face 500 error after 1.5.5 updates. It’s related to undefined PRODUCT_CODE_COLOR. We’ve fixed it temporarily. Hopes this can help.

    [15-Dec-2025 04:40:06 UTC] PHP Fatal error: Uncaught Error: Undefined constant “PRODUCT_CODE_COLOR”
    in wp-content/plugins/product-code-for-woocommerce/templates/product-meta-row.php:24

    [15-Dec-2025 04:40:16 UTC] PHP Fatal error: Uncaught Error: Undefined constant “PRODUCT_CODE_COLOR”
    in wp-content/plugins/product-code-for-woocommerce/templates/product-meta-row.php:24

    🚨 Problem Report – Initial Symptoms

    🔬 Root Cause AnalysisThe Problematic Code

    File: wp-content/plugins/product-code-for-woocommerce/templates/product-meta-row.php Line: 24

    <?php
    // ... (lines 1-23)
    
    $colorCode = get_post_meta($post->ID, PRODUCT_CODE_COLOR, true);  // ❌ LINE 24 - FATAL ERROR
    //                                      ^^^^^^^^^^^^^^^^^
    //                                      Undefined constant!
    
    // ... rest of template
    ?>
    

    Why This Failed

    1. Undefined Constant: The code references PRODUCT_CODE_COLOR as a PHP constant (without quotes)
    2. Expected Behavior: PHP constants must be defined using define('PRODUCT_CODE_COLOR', '_product_code_color')
    3. Actual Behavior: The constant was never defined anywhere in the plugin
    4. Result: PHP throws a Fatal Error, halting page execution → HTTP 500

    Missing Constant:

    PRODUCT_CODE_COLOR  // ❌ NOT DEFINED ANYWHERE

    How the Variable Was Used

    The $colorCode variable was being used later in the template to set inline CSS styling:

    <!-- Line 37 -->
    <span class="stl_codenum" style="color:<?php echo esc_html($colorCode); ?> !imortant">
        <?php echo esc_html(!$value ? __('N/A', 'product-code-for-woocommerce') : $value); ?>
    </span>
    
    <!-- Line 48 -->
    <span class="stl_codenum_second" style="color:<?php echo esc_html($colorCode); ?> !imortant">
        <?php echo esc_html(!$value_second ? __('N/A', 'product-code-for-woocommerce') : $value_second); ?>
    </span>
    

    Purpose: Allows customization of product code text color via WordPress post meta.

    ✅ The Solution – Fix Implementation

    Changed Line 24 from:

    $colorCode = get_post_meta($post->ID, PRODUCT_CODE_COLOR, true);  // ❌ Undefined constant
    

    To:

    $colorCode = get_post_meta($post->ID, '_product_code_color', true);  // ✅ String literal
    

    How to Prevent Similar Issues

    Use Defensive Coding:

    // Instead of:
    $colorCode = get_post_meta($post->ID, PRODUCT_CODE_COLOR, true);
    
    // Use:
    $meta_key = defined('PRODUCT_CODE_COLOR') ? PRODUCT_CODE_COLOR : '_product_code_color';
    $colorCode = get_post_meta($post->ID, $meta_key, true);

    @rgenck please share in dropbox!

    I have same issue and cant get rollback to fetch previous, says: “It appears there are no version to select. This is likely due to the plugin author not using tags for their versions and only committing new releases to the repository trunk.”

Viewing 2 replies - 1 through 2 (of 2 total)