• Not strictly related to WP more of a PHP syntax query.

    I found this bit of code to put a short description under a product in Woocommerce. Unfortunately it was pasted onto the help site incorrectly and so, ‘almost’ works.

    Can anyone tell me what is wrong with the last Echo, part – the &amp and quot parts, I know they need changing but PHP and coding on the fly is new to me.

    CODE START
    add_action( ‘woocommerce_after_shop_loop_item_title’, ‘lk_woocommerce_product_excerpt’, 35, 2);
    if (!function_exists(‘lk_woocommerce_product_excerpt’))
    { function lk_woocommerce_product_excerpt()

    { echo ‘<span class="excerpt">’;
    the_excerpt(); echo ‘</span>’; } }
    CODE END

    I have tried a few variants replacing the &amp with & and so on, but nothing works so far, it either crashes the site or displays the excerpt and part of the code.
    Any pointers appreciated.
    McP.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can directly write something like

    echo ‘<span class=”excerpt”>’;
    the_excerpt();
    echo ‘</span>;

    No need to use the html entities.
    This will work

    Thread Starter robmcp

    (@robmcp)

    Thanks, I tried

    add_action( ‘woocommerce_after_shop_loop_item_title’, ‘lk_woocommerce_product_excerpt’, 35, 2);
    if (!function_exists(‘lk_woocommerce_product_excerpt’))
    { function lk_woocommerce_product_excerpt()
    { echo ‘<span class=”excerpt”>’; the_excerpt(); echo ‘</span>’ } }

    I can’t tell if it is syntactically correct, but it crashes.

    Thread Starter robmcp

    (@robmcp)

    The result of the ‘wrong’ code gives this as visible on develop

    ” & lt; “span class=”& quot ” ;excerpt”& amp;” ” quot”;” & gt; ”

    My Short description test shown here

    “& lt ;”/span” &gt ;”
    but as mentioned the ‘right’ code crashes

    EDIT Sorry the code pasted in as working not as ampersand gt

    • This reply was modified 7 years, 7 months ago by robmcp.
    • This reply was modified 7 years, 7 months ago by robmcp.
    • This reply was modified 7 years, 7 months ago by robmcp.
    • This reply was modified 7 years, 7 months ago by robmcp.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding a short desc under a section/product’ is closed to new replies.