Answer the question
In order to leave comments, you need to log in
How to make a loop to get the characteristics of a woocomerce product?
There is a plugin for creating xml for unloading goods to the outlet, I decided to modify it a bit. But ran into a problem.
The plugin generates duplicate Feature Names when compiling a feed.
And it is necessary that it would be like this for fast attributes.
Here is the code that is responsible for getting the Characteristic and its parameters:
foreach ( $general_atts as $general_att ) {
$general_att_array = $general_att->get_data();
//var_dump($general_att_array);
if ( true === $general_att_array['variation'] ) {
continue;
}
if ( 1 === $general_att_array['is_taxonomy'] ) {
$tax_att = get_taxonomy( $general_att_array['name'] );
if ( ! empty( $tax_att ) ) {
foreach ( $general_att_array['options'] as $general_att_value ) {
$products .= "\n\t\t\t<param name=\"". $tax_att->labels->singular_name ."\">";
$att_term = get_term($general_att_value);
$products .="\n\t\t\t" . $att_term->name . "</param>";
}
}
} else {
$products .= "\n\t\t\t<param name=\"". $general_att_array['name'] ."\"><![CDATA[" . str_replace( ' | ', '<br> ', $general_att_array['value'] ) . "]]></param>";
}
}
}
Answer the question
In order to leave comments, you need to log in
this piece
foreach ( $general_att_array['options'] as $general_att_value ) {
$products .= "\n\t\t\t<param name=\"". $tax_att->labels->singular_name ."\">";
$att_term = get_term($general_att_value);
$products .="\n\t\t\t" . $att_term->name . "</param>";
}
$attr = [];
foreach ( $general_att_array[ 'options' ] as $general_att_value ) {
$att_term = get_term( $general_att_value );
$attr[] = $att_term->name;
}
$products .= "\n\t\t\t" . sprintf('<param name="%s">%s</param>',$tax_att->labels->singular_name,implode( ',', $attr ));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question