How to pass an attribute from a hivepress listing (dimension attribute in my case) into a woocommerce product when we create a new product via a snippet?
I would like to replace the content of my variable class_slug by the listing->dimension attribute.
In your code snippet, it is possible to get the listing object in this way.
// Get product.
$product = wc_get_product( $product_id );
$listing = null;
// Get listing ID.
$listing_id = $product->get_parent_id();
if ( $listing_id ) {
// Get listing.
$listing = \HivePress\Models\Listing::query()->get_by_id( $listing_id );
}
Then it is possible to get listing attribute information in this way.
$listing->get_your_attribute_field_name();
Please note that it can require further customization. If you are not familiar with the code customization, then please consider hiring someone for custom work https://fvrr.co/32e7LvY
Thank you for the first answer and for your reactivity!
I adapted my snippet like this, the $listing object is not null, but impossible to get the dimension attribute or any of its other attributes for that matter. The ids of the retrieved listing and of the product are however existing and not null.
Please ensure you put the correct attribute field name/slug in the code. If you are not familiar with the code customization, then please consider hiring someone for custom work https://fvrr.co/32e7LvY
I followed your instructions, unfortunately it still does not work. I have duplicated and adapted a snippet that works, which I use when I update a vendor. I took as reference your documentation:
Because the hivepress/v1/models/listing/create hook returns a listing object without information as it calls when the auto-draft listing is created
But please note that it can require further customization. If you are not familiar with the code customization, then please consider hiring someone for custom work https://fvrr.co/32e7LvY