I get this error that offer is missing in schema.
I am using the vehicle schema type. I tried using this code to add the organization and offer but it only adds the organization:
add_filter(
'hivepress/v1/models/listing/schema',
function( $schema ) {
// Get the current listing context
$listing = hivepress()->request->get_context( 'listing' );
if ( ! $listing ) {
return $schema;
}
// Add title to the schema
$schema['title'] = $listing->get_title();
// Add offers to the schema
$price = $listing->get_field( 'hp_price' ); // Replace 'hp_price' with the correct key
if ( $price ) {
$schema['offers'] = [
'@type' => 'Offer',
'price' => $price,
'priceCurrency' => 'USD', // Replace with your currency code
];
} else {
error_log( 'Price field is empty or invalid.' );
}
// Add seller details dynamically
$seller_name = $listing->get_vendor__name();
$seller_url = $listing->get_vendor__url();
if ( $seller_name ) {
$schema['seller'] = [
'@type' => 'Organization',
'name' => $seller_name,
'url' => $seller_url ?: '', // Add URL if available, or leave empty
];
} else {
error_log( 'Seller information is missing or invalid.' );
}
// Add datePosted
$created_date = $listing->get_created_date();
if ( $created_date ) {
$schema['datePosted'] = $created_date;
} else {
error_log( 'Created date is missing or invalid.' );
}
// Add validThrough if the expiration time is available
$expired_time = $listing->get_expired_time();
if ( $expired_time ) {
$schema['validThrough'] = date( 'Y-m-d\TH:i:s', $expired_time );
}
return $schema;
}
);
I have the price under the custom attribute “price” but hivepress does not show that as a schema option.
