Home > front end >  WooCommerce | Add custom text at the end of the short description
WooCommerce | Add custom text at the end of the short description

Time:06-05

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

<tbody >
    <?php if ( get_field( 'platform' ) ): ?>
        <tr>
            <td >Platform:</td>
            <td >
            <?php $terms = get_field('platform');
    if( $terms ): ?>
    <?php foreach( $terms as $term ): ?>
            <a  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

CodePudding user response:

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 >
    <?php if ( get_field( 'platform' ) ): ?>
        <tr>
            <td >Platform:</td>
            <td >
            <?php $terms = get_field('platform');
    if( $terms ): ?>
    <?php foreach( $terms as $term ): ?>
            <a  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 }

CodePudding user response:

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

  • Related