I
I
Ilya123452021-06-17 14:25:23
WordPress
Ilya12345, 2021-06-17 14:25:23

Wordoress wodocommerce can't figure out where to connect the display of attributes in the header?

Good afternoon, Seoshnik turned to the site.
The bottom line is that he received duplicate titles during import, and wants to spice it up with a crutch (add a brand to the title).
I'm in WordPress not boom boom.
In general, I found from where you can pull the brand:

defined( 'ABSPATH' ) || exit;

if ( ! $product_attributes ) {
  return;
}
?>
  <?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
    <tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
      <th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></th>
      <td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?> <?php if(wp_kses_post( $product_attribute['label'] )==='Артикул'){echo 'good';}?></td>
    </tr>
  <?php endforeach; ?>


I actually tested it next to it, it gives me what I need for the crutch, but the nuance is that I don’t know where the $product_attributes variable goes , the search for the contents of the files did not give any results.
It connects and works in the middle of the page, but I need to run it in the header where $product_attributes has not yet been initialized, and therefore it just gives an error.
Which piece of wordpress needs to be connected in order for this code to work in the header?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Nesterov, 2021-06-17
@cooder

Good afternoon.
Specifically, this code cannot be "pulled" into the header, since this is a woocommerce template file from the /plugins/woocommerce/templates/single-product/ directory, the file is product-attributes.php.
That is, this file is displayed on the product page. It cannot be taken anywhere else.
The brand in the title can be pulled out of the global $product global variable. For example -

global $product;
$brand = $product->get_name();

How exactly to do this - there may already be a variety of implementations. From $product you can pull out any data about the product. Here is a link where you can pick up methods -
https://www.businessbloomer.com/woocommerce-easily...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question