• Resolved ktatkehorne

    (@ktatkehorne)


    The above is a staging site as the upgrade of free version YITH WooCommerce Compare plugin from 2.48.0 to 3.2.0 has broken the compare button. [yith_compare_button] displays instead of the compare button (compare live site: https://practicalbathing.co.uk/product-category/walk-in-baths/)
    I have taken on the site recently and asked to update WP and plugins. The site has a bespoke theme which was written at least 5 years ago.
    In the theme inc folder there is a file called extras.php with

    function practical_compare_and_wishlist_tab( ) {

    ob_start();
    //$yith_compare = new YITH_Woocompare_Frontend();
    //add_shortcode( 'yith_compare_button', array( $yith_compare , 'compare_button_sc' ) );
    echo '
    <ul>
    <li>'.do_shortcode('[yith_compare_button]').'</li>
    <li>'.do_shortcode('[yith_wcwl_add_to_wishlist]').'</li>
    
    </ul>';
    $content=ob_get_contents();
    ob_end_clean();
    echo $content;

    };

    add_action( ‘woocommerce_after_add_to_cart_button’, ‘practical_compare_and_wishlist_tab’, 100, 0 );

    BTW as a test I ativated WP 2025 theme and the compare button works so I know this is theme related.
    Do you have any clues as to what has changed between version 2.48.0 and 3.2.0 that would cause the shortcode not to work?

    This is the error message in the error log:
    E_USER_NOTICE: Function do_shortcode_tag was called incorrectly. Attempting to parse a shortcode without a valid callback: yith_compare_button Please see Debugging in WordPress for more information. (This message was added in version 4.3.0.) in /mnt/BLOCKSTORAGE/home/1101307.cloudwaysapps.com/gghcuutkcq/public_html/wp-includes/functions.php on line 6121


    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello there,
    thanks for contacting us!

    Maybe the problem is due to the class name, since the correct one is:

    YITH_WooCompare_Frontend();

    Additionally, you can use the following code to call the instance of the class:

    YITH_WooCompare_Frontend::instance();

    Could you check it, please?

    Best regards.

    Thread Starter ktatkehorne

    (@ktatkehorne)

    Hi

    Thanks for reaching out.
    I’ve just noted the code I added above looks like 2 lines are commented out but they should have read:
    Checking what you have asked me to check, they look the same:

    function practical_compare_and_wishlist_tab( ) {

    ob_start();
    $yith_compare = new YITH_Woocompare_Frontend();
    add_shortcode( 'yith_compare_button', array( $yith_compare , 'compare_button_sc' ) );
    echo '
    <ul>
    <li>'.do_shortcode('[yith_compare_button]').'</li>
    <li>'.do_shortcode('[yith_wcwl_add_to_wishlist]').'</li>

    </ul>';
    $content=ob_get_contents();
    ob_end_clean();
    echo $content;

    };

    add_action( ‘woocommerce_after_add_to_cart_button’, ‘practical_compare_and_wishlist_tab’, 100, 0 );

    Hi there,

    Please replace your code with this new one:

    function practical_compare_and_wishlist_tab() {

    ob_start();
    echo '<ul>
    <li>' . do_shortcode('[yith_compare_button]') . '</li>
    <li>' . do_shortcode('[yith_wcwl_add_to_wishlist]') . '</li>
    </ul>';
    $content = ob_get_contents();
    ob_end_clean();
    echo $content;
    };

    add_action('woocommerce_after_add_to_cart_button', 'practical_compare_and_wishlist_tab', 100, 0);

    Could you check it, please?

    Best regards.

    Thread Starter ktatkehorne

    (@ktatkehorne)

    Hi
    Thank you – so that now works…It is this one that doesn’t still:

    function woocommerce_after_shop_loop_item(){

     $yith_compare = new YITH_WooCompare_Frontend();
     add_shortcode( 'yith_compare_button', array( $yith_compare , 'compare_button_sc' ) );
     echo '
     <ul>
     <li>'.do_shortcode('[yith_compare_button]').'</li>
     <li>'.do_shortcode('[yith_wcwl_add_to_wishlist]').'</li>
    
     </ul>';

    }
    add_action(‘woocommerce_after_shop_loop_item’,’woocommerce_after_shop_loop_item’);

    Hi there,

    Simply keep the following code to display the button on the shop and single product page:

    if ( ! function_exists( 'practical_compare_and_wishlist_tab' ) ) {
    function practical_compare_and_wishlist_tab() {

    ob_start();
    echo '<ul>
    <li>' . do_shortcode('[yith_compare_button]') . '</li>
    <li>' . do_shortcode('[yith_wcwl_add_to_wishlist]') . '</li>
    </ul>';
    $content = ob_get_contents();
    ob_end_clean();
    echo $content;
    };
    add_action('woocommerce_after_add_to_cart_button', 'practical_compare_and_wishlist_tab', 100 );
    add_action('woocommerce_after_shop_loop_item', 'practical_compare_and_wishlist_tab', 100 );
    }

    Could you check it, please?

    Best regards.

    Thread Starter ktatkehorne

    (@ktatkehorne)

    Hi
    Thank you for your help so far! So I tried your last bit of code and that didn’t quite work as it lost it’s buttons. I have managed to add the code into function woocommerce_after_shop_loop_item(){} and everything is working fine now except that I have noticed that now this plugin is updated it adds the compare link twice as a tiny white text link. I restored the site so that my extras.php was back to it’s original version before I corrected the code and I notice that the compare link is added twice in that page too. The second “Compare” is tiny and white but still just visible. When I inspect the page the same link is there twice.

    • This reply was modified 10 months, 1 week ago by ktatkehorne.
    Juan Coronel

    (@juaancmendez)

    Hello there,

    Maybe that’s because you need to enable the following option if you want to display the button with the shortcode on the shop page:

    General Settings > "Compare" button > Show compare in: > Product Pages

    Currently, everything looks fine on your staging, so if you still need assistance, I’ll have to review the issue from your site to see what’s going on.

    Please let me know.

    Best regards.

    Thread Starter ktatkehorne

    (@ktatkehorne)

    Thank you so much. That has worked! The setting was on Shop Pages. It tried change to “Both” and that was still not right. Now it is set to just “Product Pages” and all is working fine.

    Thank you again.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘[yith_compare_button] shortcode not rendering’ is closed to new replies.