skip to Main Content

I am trying to add this code in functions.php but it is giving me the error

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;
};

I want this content to be added after the product description

2

Answers


  1. Chosen as BEST ANSWER

    click here to open the error image

    Hello, the error keeps appearing, please could you help me solve it.

    syntax error, unexpected 'endif' (T_ENDIF)
    

  2. Use the following code in functions.php or create a child theme. I have used action hook.

    add_action( 'woocommerce_after_single_product_summary', 'misha_add_custom_info', 10 );
    
    function misha_add_custom_info() {
      if ( is_singular( 'product' ) ) {
        ?>
        <table class="vertical-menu">
          <tbody>
            <tr>
              <td class="cabecera">
              <?php if( get_field('download') ): ?>
                <strong><i class="icon-checkmark"></i>Download:</strong>
              <?php endif; ?>
              </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>
              <?php endif; ?>
              </td>
              <td class="detail">
                <strong><?php the_field('color'); ?><?php endif; ?></strong>
              </td>
            </tr>
          </tbody>
        </table>
        <?php
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search