Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 7 days ago.
Improve this questionI am using Elementor, WooCommerce and WP all import Pro to import an XML file with Car Data. My problem is that the Equipment of the car varies between all of them and is a lot, so i cant create attributes or tags for all of them by hand, i want to automatically import every Equipment detail of the Car to display it. For example a short snippet:
<equipment>
<descritpion>ABS</descritpion>
<manufacturer_code>FRE02</manufacturer_code>
<normalized_code>FRE02</normalized_code>
<type>standard</type>
</equipment>
<equipment>
<descritpion>Airbag driver</descritpion>
<manufacturer_code>SIC01</manufacturer_code>
<normalized_code>SIC01</normalized_code>
<type>standard</type>
</equipment>
so in this case i would like to save ABS and Airbag driver as attributes of my Product or even just make it as a post. Whaever works to import every attribute of the car. Or is there a way to work with XML data directly in Elementor or the WP-Editor? Thanks a lot for your help
I tried some short Code the WP all import support sent me but it didn't really help so im kind of on my own. I would like to either safe it as a product or make a post for it, maybe some of you have a better idea. There is nothing decided yet and i am trying for a couple of days to get this to work. This is my last resort here guys.
Edit: A support member of WP all import gave me this code snippet, but i dont know what to do with it, or how to change it to work with my XML file...
/**
* @param $post_id
* @param $xml
*/
function wp_programator_automatically_import_wpai_params($post_id, $xml)
{
$atts = [];
// The $xml is a SimpleXML object
// Scrub through the PARAM attributes and add these to product
foreach ( $xml->PARAM as $param ) {
// Get attribute name
$name = $param->PARAM_NAME->__toString();
// Get attribute value
$value = $param->VAL->__toString();
// The WC attribute taxonomy is prefixed with pa_, vuild the slug here
$slug = 'pa_'.wc_sanitize_taxonomy_name($name);
// Create the attribute
wc_create_attribute(['name' => $name]);
// Add the product to the taxonomy we just created
wp_set_object_terms( $post_id, wc_sanitize_taxonomy_name($value), $slug, true );
// Add to the attributes data
// This is needed for attributes to display in the WP admin
$atts[$slug] = [
'name'=> $slug,
'value'=> $value,
'is_visible' => '1',
'is_variation' => '0',
'is_taxonomy' => '1'
];
}
// Update the _product_attributes meta - this is where the attribute data are stored for products
$product = wc_get_product($post_id);
$product->update_meta_data('_product_attributes', $atts);
$product->save();
}```