• Resolved purbeckpixels

    (@purbeckpixels)


    I have a function in the site I’m in the process of updating to version 3 which adds/appends an anchor link to the product’s short description linking to the (long) description:

    // Add anchor link/tag to short description linking to long description
    add_filter( 'woocommerce_short_description', 'storefront_short_description_with_anchor', 10, 1 );
    function storefront_short_description_with_anchor( $product_short_description ) {
        global $product;
        global $post;
    
        if ( is_single() && is_product() )
            $product_short_description = $product_short_description . '<p><a href="#learn-more" rel="learn-more">Learn more about ' . $post->post_title . '</a></p>';
    
        return $product_short_description;
    }

    It worked flawlessly in 2.6 (you can see an example on the live site running 2.6.14 here) and 3.0 and 3.0.1, but since 3.0.2 the function is also adding the '<p><a href="#learn-more" rel="learn-more">Learn more about ' . $post->post_title . '</a></p>' code to the variations form’s variation_description and thus when a variation is selected, to the woocommerce-variation-description div, which means once a variation is selected the '<p><a href="#learn-more" rel="learn-more">Learn more about ' . $post->post_title . '</a></p>' code is outputted again below the variations table and above the price, e.g.:

    Screenshot: https://pasteboard.co/8TPIq5Ty3.jpg

    Like I said, it worked fine in 2.6, 3.0 and 3.0.1 but I can’t work out what changed in 3.0.2 to cause this behaviour. A bug? Or my limited programming skills? I could hide the second output with CSS, but I’d rather fix it properly.

    • This topic was modified 7 years, 10 months ago by purbeckpixels.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Have not tested it but have you tried the filter:

    woocommerce_format_content

    Good luck!

    Thread Starter purbeckpixels

    (@purbeckpixels)

    This has to be a bug. I’ve tried all the usual ways of narrowing down the issue, I even removed all short descriptions from the site using…

    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );

    … but still the function adds the '<p><a href="#learn-more" rel="learn-more">Learn more about ' . $post->post_title . '</a></p>' code to the variation_description form and woocommerce-variation-description div. I rolled back to version 3.0.1 to double-check it worked fine and it did. What changed in version 3.0.2 to cause this? It’s frustrating.

    Thread Starter purbeckpixels

    (@purbeckpixels)

    Narrowed it down to this code change from version 3.0.1 to 3.0.2 (in woocommerce/includes/wc-formatting-functions.php):

    https://plugins.trac.www.ads-software.com/changeset?old_path=%2Fwoocommerce&old=1631564&new_path=%2Fwoocommerce&new=1636312&sfp_email=&sfph_mail=#file995

    3.0.1: return apply_filters( 'woocommerce_format_content', wpautop( do_shortcode( wp_kses_post( $raw_string ) ) ), $raw_string );

    3.0.2: return apply_filters( 'woocommerce_format_content', apply_filters( 'woocommerce_short_description', $raw_string ), $raw_string );

    Thread Starter purbeckpixels

    (@purbeckpixels)

    If anyone else is experiencing the same issue, here’s a function that filters woocommerce_format_content to use the code from woocommerce/includes/wc-formatting-functions.php versions 2.6.x and 3.0/3.0.1:

    add_filter( 'woocommerce_format_content', 'storefront_filter_woocommerce_format_content', 10, 1 );
    function storefront_filter_woocommerce_format_content( $raw_string ) {
    	global $product;
    	
    	if ( is_singular('product') )
    		apply_filters( 'storefront_filter_woocommerce_format_content', wpautop( do_shortcode( wp_kses_post( $raw_string ) ) ), $raw_string );
    }

    Thanks to @darius00klokj for pointing me in the right direction.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Variation description display issue’ is closed to new replies.