skip to Main Content

How can I put the following code at the end of my short product description? (WooCommerce)

<tbody class="table-hover">
    <?php if ( get_field( 'platform' ) ): ?>
        <tr>
            <td class="text-left prd-platform ">Platform:</td>
            <td class="text-left trd-platform">
            <?php $terms = get_field('platform');
    if( $terms ): ?>
    <?php foreach( $terms as $term ): ?>
            <a class="acflinkcls" href="<?php echo esc_url( get_term_link( $term ) ); ?>"><?php echo esc_html( $term->name ); ?></a>
    <?php endforeach; ?>
    <?php endif; ?>
            </td>
        </tr>
    <?php endif; ?>
</tbody>
</table> 

I want this code to be part of my short product description
Thanks for guiding me

2

Answers


  1. It seems to me, you have two alternatives:

    1: edit your theme_name/woocommerce or use child_theme. (Personally I prefer to use a child theme as a solution.)

    2: you may use woocommerce_short_description to add your code.

    3: add the following code in functions.php of your theme. you will see functions.php in the following path: wp-content/teme_name/functions.php

    add_action( 'woocommerce_single_product_summary', 'sally_below_single_product_summary', 20 );
    function sally_below_single_product_summary() {
    ?>
    <tbody class="table-hover">
        <?php if ( get_field( 'platform' ) ): ?>
            <tr>
                <td class="text-left prd-platform ">Platform:</td>
                <td class="text-left trd-platform">
                <?php $terms = get_field('platform');
        if( $terms ): ?>
        <?php foreach( $terms as $term ): ?>
                <a class="acflinkcls" href="<?php echo esc_url( get_term_link( $term ) ); ?>"><?php echo esc_html( $term->name ); ?></a>
        <?php endforeach; ?>
        <?php endif; ?>
                </td>
            </tr>
        <?php endif; ?>
    </tbody>
    </table>  
    
    <?php }
    
    Login or Signup to reply.
  2. Adding your custom text at the end of the short description content, (not for variable products):

    add_filter( 'woocommerce_short_description', 'add_text_after_excerpt_single_product', 20, 1 );
    function add_text_after_excerpt_single_product( $post_excerpt ){
        if ( ! $short_description )
            return;
    
        // Your custom text
        $post_excerpt .= '<ul class="fancy-bullet-points red">
        <li>Current Delivery Times: Pink Equine - 4 - 6 Weeks, all other products 4 Weeks</li>
        </ul>';
    
        return $post_excerpt;
    }
    

    Follow the URL below to resolve your issue:

    Add Text under Single Product Short Description in Woocommerce

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search