0

Jut updated wordpress and woocommerce to the latest versions. Unfortunately im getting a 500 Internal Server somewhere in the following lines:

add_action( 'woocommerce_before_shop_loop_item', 'attribute_img_loop', 20 );
function attribute_img_loop() {
        global $post;
        $attribute_names = array( 'pa_sertifikalar' ); // Add attribute names here and remember to add the pa_ prefix to the attribute name
        // echo '<script>alert('.$attribute_names.');</script>';

            
        foreach ( $attribute_names as $attribute_name ) {
            $taxonomy = get_taxonomy( $attribute_name );
            
            if ( $taxonomy && ! is_wp_error( $taxonomy ) ) {
                $terms = wp_get_post_terms( $post->ID, $attribute_name );
                $terms_array = array();
            
                if ( ! empty( $terms ) ) {
                    
                    echo '
                            <table class="combs" cellspacing="0">
                                <tbody>
                                        <tr>                        
                                            <td>                            
                                                <ul class="nm-variation-control ul-control-certificate">';                                                  
                                                    foreach ( $terms as $term ) {
                                                        $thumb_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
                                                        $image_id = absint( get_term_meta( $term->term_id, 'nm_pa_image_thumbnail_id', true ) );
                                                        $img_src = ( $image_id ) ? wp_get_attachment_url( $image_id ) : '';         
                                                        $archive_link = get_term_link( $term->slug, $attribute_name );
                                                        $full_line = '<li><div class="lcrap"><img id="c'. $image_id .'" data-src="'. $img_src .'" alt="" class="lazyload" alt="'. $term->name .'" /></div></li>';
                                                        array_push( $terms_array, $full_line );
                                                    }
                                                    // echo $taxonomy->labels->name . ' ' . implode( $terms_array, '-- ' );
                                                    echo implode( $terms_array, '');
                                                    
                                          echo '</ul>
                                            </td>
                                        </tr>
                                </tbody>
                            </table>';                                                  
                                                    
                }
                            
            }
        }
}

Just added echo '<script>alert('.$attribute_names.');</script>'; to check the output from the $attribute_names = array( 'pa_sertifikalar' ); part and saw it returns a

function Array() {
    [native code]
}

Logfiles are saying:

The get_woocommerce_term_meta function is deprecated since version 3.6. Replace with get_term_meta.

Replaced it with get_term_meta - still the same. Any idea whats going on here?

3
  • 1
    What’s the error message say? Nov 23, 2022 at 14:39
  • check your PHP error log to find out what the error message is, and then edit your question to include it here
    – Tom J Nowell
    Nov 23, 2022 at 14:47
  • Updated - The get_woocommerce_term_meta function is deprecated since version 3.6. Replace with get_term_meta. Replaced it with get_term_meta - still the same.
    – evavienna
    Nov 23, 2022 at 15:38

1 Answer 1

0

Problem solved (thx a lot to ChrisHaas)

replacing

 echo implode( $terms_array, '');

with

echo implode('', $terms_array); 

fixed it.

Historically the order of these parameters didn't matter, however as of PHP 7.4 passing the array first was deprecated and it was completely removed in PHP 8.0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.