Tagged: 

Viewing 30 posts - 1 through 30 (of 35 total)
  • Author
    Posts
  • #780070

    Hello,
    I noticed that if I make the page product with the Layout Builder, the schema for the product in the application/ld+json format is not present in the product page.

    Do you know how to solve this problem?

    Thanks for support

    #780145

    Hey blinkerart!

    Can you please provide a link of your page for us?

    Best regards,
    Basilis

    #780176

    Yes sure,
    thank you

    #781073

    Hi Basilis,
    do you have any news about this issue?
    thank you

    #782169

    Hi,

    That markup is not available in the theme or in the Woocommerce plugin by default so you need to use a plugin or add the script manually. Please try the following plugins. You need to install both.

    // https://wordpress.org/plugins/wpsso/
    // https://wordpress.org/plugins/wpsso-schema-json-ld/

    Best regards,
    Ismael

    #782229

    Sorry Ismael,
    I think you are wrong.

    I’ve just tested a new WordPress installation with Enfold and WooCommerce only, not other plugins installed.
    If on the product page I am not using the layout builder, in the html page there is the correct output of the json

    <script type="application/ld+json">{"@graph":[{"@context":"http:\/\/schema.org\/","@type":"Product","@id":"http:\/\/localhost\/wordpress\/prodotto\/flying-ninja\/","url":"http:\/\/localhost\/wordpress\/prodotto\/flying-ninja....
    .....

    Instead using the layout builder there is no the <script type=”application/ld+json”>.
    Is this a bug?

    thank you for support

    #782232

    Enfold uses its own html markup in the layout elements and not the markup provided by woocommerce.

    #782249

    I know it, but you are talking about the microdata markup on the single element.
    I am talking about the <script type=”application/ld+json”> that is in the <head>.

    With layout builder > no json
    Without layout builder > yes json

    In my opinion the layout builder disable some function that is responsible for the output of the json LD for products.

    #782700

    Hey!

    Ah. Yes, you’re right. Please add this hook in the functions.php file. This is based on the plugin’s WC_Structured_Data class.

    add_action( 'wp_footer', 'ava_product_schema_markup' );
    function ava_product_schema_markup() {
    	global $post, $product;
    	$builder = get_post_meta($post->ID, '_avia_builder_shortcode_tree', true);
    
    	if ( ! is_object( $product ) ) {
    		global $product;
    	}
    
    	if ( ! is_a( $product, 'WC_Product' ) ||  $builder == '' ) {
    		return;
    	}
    
    	$shop_name       = get_bloginfo( 'name' );
    	$shop_url        = home_url();
    	$currency        = get_woocommerce_currency();
    	$markup          = array();
    	$markup['@type'] = 'Product';
    	$markup['@id']   = get_permalink( $product->get_id() );
    	$markup['url']   = $markup['@id'];
    	$markup['name']  = $product->get_name();
    
    	if ( apply_filters( 'woocommerce_structured_data_product_limit', is_product_taxonomy() || is_shop() ) ) {
    		WC_Structured_Data::set_data( apply_filters( 'woocommerce_structured_data_product_limited', $markup, $product ) );
    		return;
    	}
    
    	$markup_offer = array(
    		'@type'         => 'Offer',
    		'priceCurrency' => $currency,
    		'availability'  => 'http://schema.org/' . $stock = ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
    		'sku'           => $product->get_sku(),
    		'image'         => wp_get_attachment_url( $product->get_image_id() ),
    		'description'   => $product->get_description(),
    		'seller'        => array(
    			'@type' => 'Organization',
    			'name'  => $shop_name,
    			'url'   => $shop_url,
    		),
    	);
    
    	if ( $product->is_type( 'variable' ) ) {
    		$prices = $product->get_variation_prices();
    
    		$markup_offer['priceSpecification'] = array(
    			'price'         => wc_format_decimal( $product->get_price(), wc_get_price_decimals() ),
    			'minPrice'      => wc_format_decimal( current( $prices['price'] ), wc_get_price_decimals() ),
    			'maxPrice'      => wc_format_decimal( end( $prices['price'] ), wc_get_price_decimals() ),
    			'priceCurrency' => $currency,
    		);
    	} else {
    		$markup_offer['price']    = wc_format_decimal( $product->get_price(), wc_get_price_decimals() );
    	}
    
    	$markup['offers'] = array( apply_filters( 'woocommerce_structured_data_product_offer', $markup_offer, $product ) );
    
    	if ( $product->get_rating_count() ) {
    		$markup['aggregateRating'] = array(
    			'@type'       => 'AggregateRating',
    			'ratingValue' => $product->get_average_rating(),
    			'ratingCount' => $product->get_rating_count(),
    			'reviewCount' => $product->get_review_count(),
    		);
    	}
    
    	if(is_singular('product'))
    	{
    			echo '<script type="application/ld+json">' . wp_json_encode( $markup ) . '</script>';
    	}
    }

    Cheers!
    Ismael

    #782897

    Hello Ismael,

    I have a lot of errors, do you?

    Fatal error: Uncaught Error: Call to undefined method WC_Product_Simple::get_name()
    Stack trace: …

    #783248

    Hey!

    I don’t see any errors when I add the filter and the JSON-LD markup is being applied to the product page when using the advance layout builder. Please make sure that you have the latest version of the plugin and that there is no syntax error in the filter.

    Regards,
    Ismael

    #786214

    Updated to WC 3.0.5. Now it looks like everything is ok.
    Thanks for support.

    #786468

    Hi blinkerart,

    Glad you got it working for you! :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #788188

    Hello Ismael,
    the hook you give us breaks the functionality of the search tool in the WooCommerce > Orders page.
    It breaks both the filter and the search.

    I don’t really know why, but this is.

    Do you have any idea because of what?

    thanks

    #789144

    Hi,

    The hook is braking the backend search?
    Are you sure about that?
    It is strange as it shouldnt it is supposed to work only on front end.

    Can u share us access please?

    Best regards,
    Basilis

    #789166

    Sorry Basilis,
    my bad… I completely screw up.
    I’ve just debugged line by line. The code responsible for that was another that hooks into the pre_get_posts.
    Really sorry again and thanks for being so gentle.

    #789290

    Hi,

    Thanks for the feedback, so everything is working as it should now?

    Best regards,
    Rikard

    #789334

    Yes thanks

    #789365

    Hi,

    We glad that your problem was solved :)

    Best regards,
    John Torvik

    #799369

    Hello guys,

    sorry to disturb again, but is it correct to have in my search console all the structured data with “Markup: schema.org”, instead for the products are “Markup: mydomain.com”

    Of course mydomain is an example… there it goes the domain of the site I installed your code above.

    Thanks for support

    #800067

    Hi,

    is your last post related to thread’s title? if not please always open a new ticket for a new question, cause otherwise it gets quite confusing for us.

    What you see inside your console should be pretty normal and default behavior. However, you can use a plugin like Yoast SEO to have better results.

    Best regards,
    Andy

    #800087

    Hello Andy,

    it is related to the thread, because the structured data are generated from the code that Ismael wrote.
    And about Yoast SEO, it has nothing to do about the WooCommerce Product structured data.
    So please let me know about my question,
    thanks

    #800640

    Hi,

    If you are looking for your schema, it should be pointing there yes, as that is what been called.

    Best regards,
    Basilis

    #813695

    Hello,

    I found an error in the Ismael code.
    Where there is $this->set_data at line 24, we are no in object context.
    This will cause a fatal error.

    Thanks

    #814721

    Hi,

    Happy you got it solved and we do appreciate for sharing it.

    Thank you

    Best regards,
    Basilis

    #814828

    Hello Basilis,

    I didn’t solved it, I’ve just found the problem.
    thanks

    #815030

    Hi blinkerart,

    Do you still need our help or you can take it from here? If you need help, please specify your question in more detail.

    Best regards,
    Victoria

    #815280

    The code that Ismael give us make a fatal error!
    $this->set_data at line 24, we are no in object context.
    Can not use $this if you are not inside a class.

    thanks

    #817604

    Hi!

    Thank you for the info. Where do you see the error? Is it on the actual product or the product archive pages? We modified the code a bit.

    Best regards,
    Ismael

    #817616

    I saw the errore in the log.
    I will test the new code and I will let you know.
    Thanks

Viewing 30 posts - 1 through 30 (of 35 total)
  • The topic ‘application/ld+json not present in WooCommerce Product built with Layout Builder’ is closed to new replies.