@Oviplokos

Чем заменить return чтобы работал код?

Помогите разобраться. Добавляю возможность отображения атрибутов в каталоге товаров, но не могу понять в чем моя ошибка.

Сам код:
spoiler
public function the_attributes( $product = null, $element, $show_weight = null, $show_dimensions = null, $skip_atts = null, $single_product = null ) {

    $out = '';
    $out_middle = '';

    if ( isset( $product ) ) {
      if ( is_object( $product ) ) {

        if ( $show_weight ) {
          if ( $product->has_weight() ) {
            $weight = $product->get_weight();
            $unit = esc_attr( get_option( 'woocommerce_weight_unit' ) );
          }
        }
$out_middle .= '	<table><tbody>';
        if ( $show_dimensions ) {
          if ( $product->has_dimensions() ) {
            $dimensions = wc_format_dimensions( $product->get_dimensions( false ) );
          }
        }

       		$colon = get_option( 'wcsa_remove_semicolon' ) == 'yes' ? ' ' : ': ';
        $hide_labels = get_option( 'woocommerce_show_attributes_hide_labels' );
        // check if they choose span element over li
        if ( get_option( 'woocommerce_show_attributes_span' ) == 'yes' ) {
          $element = 'span';
        }

       		if ( ! $skip_atts ) {

          $attributes = $this->get_attributes( $product, $single_product );

          if ( ! $attributes ) {
            return;
          }

          foreach ( $attributes as $attribute ) {

            $class_string = sanitize_title( strip_tags( $attribute['value'] ) );

            $out_middle .= '<' . esc_attr( $element ) . ' class="' . esc_attr( sanitize_title( $attribute['label'] ) ) . ' ' . esc_attr( $class_string ) . '">';


            // Hide labels if they want to
            if ( 'yes' != $hide_labels ) {
                
              // PolyLang translation support
              if ( function_exists( 'pll__' ) ) {
                $translation = pll__( $attribute['label'] );
                $attribute['label'] = ( ! empty( $translation ) ) ? $translation : $attribute['label'];
              }
              // WPML translation support
              if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
                $translation = apply_filters( 'wpml_translate_single_string', $attribute['label'], 'WordPress', 'taxonomy singular name: '. $attribute['label'] );
                  $attribute['label'] = ( ! empty( $translation ) ) ? $translation : $attribute['label'];
                  
              }	
            }
     
{
 
$out_middle .= '<tr><td><span class="attribute-label"> ' .
sprintf( __( '%s', '<b>woocommerce-show-attributes</b>' ), esc_html( $attribute['label'] ) )
. '</td></span>' . $colon  ;
                  
            $out_middle .= '<td><span class="attribute-value">';
            $out_middle .= $attribute['value'];

            $out_middle .= '</span></td></tr></' . esc_attr( $element ) . '>';
            
} 
  

          } // ends foreach attribute 
        
        }

        // Add weight and dimensions if they opted in

        if ( ! empty( $weight ) ) {
          $unit = empty( $unit ) ? '' : $unit;
          // weight
          $out_middle .= '<' . esc_attr( $element ) . ' class="show-attributes-weight">';
          // Hide labels if they want to
          if ( $hide_labels != 'yes' ) {
            $out_middle .= '<span class="attribute-label">' . __( 'Weight', 'woocommerce-show-attributes' ) . $colon . ' </span> ';
          }
          $out_middle .= '<span class="attribute-value">' . esc_html( $weight ) . ' ' . esc_html( $unit ) . ' </span></' . esc_attr( $element ) . '>';
          if ( 'span' == $element ) {
            $out_middle .= '<br />';
          }
        }

        if ( ! empty( $dimensions ) ) {
          // dimensions
          $out_middle .= '<' . esc_attr( $element ) . ' class="show-attributes-dimensions">';
          // Hide labels if they want to
          if ( $hide_labels != 'yes' ) {
            $out_middle .= '<span class="attribute-label">' . __( 'Dimensions', 'woocommerce-show-attributes' ) . $colon . ' </span> ';
          }
          $out_middle .= '<span class="attribute-value">' . esc_html( $dimensions ) . '</span></' . esc_attr( $element ) . '>';
          if ('span' == $element) {
            $out_middle .= '<br />';
          }
        }
$out_middle .= (' </tbody></table>');
        
if ( $out_middle ) {
          $out = ('li' == $element) ? '<ul ' : '<div ';
          $out .= 'class="attribut">' . $out_middle;
          $out .= ('li' == $element) ? '</ul>' : '</div>';
}
    

      }
    }
    return $out;
  }


Беру функцию из плагина, добавляю ее в function.php woocommerce, чтобы поменять порядок отображения, т.к. плагин выводит только в самый конец карточки. Но код не работает по причине того, что в его конце стоит return и он отваливает все последующие коды. Если return заменить на echo, то не работает уже сам код. Какой может быть выход?

Визуалку прилагаю. Ссылка на страницу тут.

spoiler
5e9484c21e2d2100209345.jpeg


spoiler
5e9484d88d07f281165447.jpeg
  • Вопрос задан
  • 286 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы