• Resolved Jaime

    (@wilfredo1234)


    Hello, can you help me please, I am trying to add this code in functions.php but it is giving me the error, please could you help me solve it, I will be grateful, thank you.

    add_filter( 'the_content', 'misha_add_something_description_tab' );
    function misha_add_something_description_tab( $content ){
        if( is_product() ) { // I recommend to always use this condition
            $content .= '<table class="vertical-menu">
        <tbody>
            
            <tr>
                <td class="cabecera"><?php if( get_field('download') ): ?><strong><i class="icon-checkmark"></i>Download:</strong></td>
                <td class="detail"><strong><?php the_field('download'); ?><?php endif; ?></strong></td>
            </tr>
            
            <tr>
                <td class="cabecera"><?php if( get_field('color') ): ?><strong><i class="icon-checkmark"></i>Color:</strong></td>
                <td class="detail"><strong><?php the_field('color'); ?><?php endif; ?></strong></td>
            </tr>
        </tbody>
    </table>';
        }
        return $content;
    };
Viewing 4 replies - 1 through 4 (of 4 total)
  • Stef

    (@serafinnyc)

    Hello @wilfredo1234 how dare Misha write bad code. Anything on his site is usually outdated by now since he’s not really doing much anymore.

    Try This

    add_filter( 'the_content', 'misha_add_something_description_tab' );
    
    function misha_add_something_description_tab( $content ) {
        if( is_product() ) { // I recommend to always use this condition
            ob_start(); // Start output buffering
            ?>
            <table class="vertical-menu">
                <tbody>
                    <tr>
                        <td class="cabecera">
                            <?php if( get_field('download') ): ?>
                                <strong><i class="icon-checkmark"></i>Download:</strong>
                        </td>
                        <td class="detail">
                            <strong><?php the_field('download'); ?></strong>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="cabecera">
                            <?php if( get_field('color') ): ?>
                                <strong><i class="icon-checkmark"></i>Color:</strong>
                        </td>
                        <td class="detail">
                            <strong><?php the_field('color'); ?></strong>
                            <?php endif; ?>
                        </td>
                    </tr>
                </tbody>
            </table>
            <?php
            $content .= ob_get_clean(); // Get the buffered content and append it to $content
        }
        return $content;
    }

    In this corrected version, the HTML is separated from the PHP logic by using ob_start() and ob_get_clean().

    This way, the PHP code executes properly, and the generated HTML is correctly appended to the content.

    Thread Starter Jaime

    (@wilfredo1234)

    thank you very much it works wonderfully

    • This reply was modified 6 months, 1 week ago by Jaime.
    Stef

    (@serafinnyc)

    ???? welcome

    Plugin Support ckadenge (woo-hc)

    (@ckadenge)

    Hi @wilfredo1234,

    I’ll mark this thread as resolved now. If you have any further questions, I recommend creating a new thread.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘URGENT: woocommerce error code when trying to add custom field after product’ is closed to new replies.