A few custom codes I’ve written for woocommerce aren’t working properly after updating to woocommerce 3. In this particular case, it’s the woocommerce_available_variation filter. I used it to dynamically insert product variation descriptions based on the product attributes.

As of now I am getting this error message:

Catchable fatal error: Object of class WC_Product_Download could not be converted to string in /home/silent48/public_html/wp/wp-content/plugins/woocommerce/includes/wc-product-functions.php on line 376

What would I need to do to the below code to make it compliant with 3.0?

add_filter( 'woocommerce_available_variation', 'change_variation_descriptions');
function change_variation_descriptions( $descriptions) {


global $post, $woocommerce;


    $basicmp3des = '<div class="licensedetails">
                    <li>-Delivered in mp3 format instantly after purchase</li>
                    <li>-Synchronization rights are granted</li>
                    <li>-One commercial use is permitted (ie: mixtape, album, etc)</li>
                    <li>-You may distribute up to 5000 profitable units</li>
                    <li>-Includes non-exclusive contract agreement (e-signed at checkout)</li>
                    <li>-Send me a quote to inquire about Exclusive License purchase!</li>
                    </div>';    





     foreach ( $descriptions as $description ) {
        $variation =  wc_get_formatted_variation($description, true );


            if (strpos($variation, 'Basic License') !== false && strpos($variation, 'mp3') !== false ) {
                    $descriptions['variation_description'] = $basicmp3des;
            }

     }

            return $descriptions;     
}   

Read more here: woocommerce_available_variation filter no longer working after Woocommerce 3 update


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: