Event Snippet with Woo Products

  • Hello everybody,

    I try to setup rich snippets for our site. We use Woocommerce products together with ACF to show and sell our events. Is there a way wo make the events-schema work on woocommerce products? We have made a special product-category especially for our events so we could define this schema information to every product that sits in this category.

    Thank you very much.

    Kind regards,
    Stefan

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello,

    Thank you for contacting the support.

    Please add the following code to your theme’s functions.php file and see if that helps.
    Filter code to change Schema to Event on WC Products page:

    add_filter( "rank_math/json_ld", function( $data, $jsonld ) {
      	if ( ! is_singular( 'product' ) ) {
      		return $data;
      	}
    
    	 	unset( $data['richSnippet'] );
    
    	 	$product_id = $jsonld->post_id;
    	 	// Use get_post_meta( $product_id, '_meta_key', true ); to get the meta value for event
    	 	$data['richSnippet'] = array(
    	 		'@context' => 'https://schema.org',
    	 		'@type' => 'MusicEvent',
    	 		'name' => $jsonld->parts['title'],
    	 		'description' => $jsonld->parts['desc'],
    	 		'url' => $jsonld->parts['url'],
    	 		'eventStatus' => get_post_meta( $product_id, '_meta_key', true ),
    	 		'location' => array(
    	 			'@type' => 'Place',
    	 			'name'  => 'Venue Name',
    	 			'url'   => 'venue_url',
    	 			'address' => array(
    	 				'@type' => 'PostalAddress',
    	 				'streetAddress' => 'Street Address',
    	 				'addressLocality' => 'Address Locality',
    	 				'addressRegion' => 'Address Region',
    	 				'postalCode' => 'Postal code',
    	 				'addressCountry' => 'Country',
    	 			),
    	 		),
    	 		'startDate' => '2019-03-06T15:20',
    	 		'endDate'   => '2019-03-06T15:20',
    	 		'performer' => array(
    	 			'@type' => 'Person',
    	 			'name'  => 'Jack'
    	 		),
    	 	);
    	 	return $data;
      }, 20, 2 );

    Let us know how it goes.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this ticket.