I am importing products via Product Import Export for WooCommerce by WebToffee, I then have a function that pulls data from an API and populates the data in each imported product.
Everything works perfectly, except Yoast breadcrumbs don’t show properly when I view the product. The breadcrumbs on the frontend will say e.g.
Shop » Product Name
instead of the full category and sub-category breadcrumb trail.
The only way I can successfully get the breadcrumbs to show properly is by manually editing the product and clicking update, it then shows correctly, as in:
Shop » Workwear » High Visibility » Hi Vis Polo Shirts & T-Shirts » Product Name
This would be fine, except I will be importing thousands of products in one sitting so I need a programmatic solution to add to my function which will make the breadcrumbs display properly on the frontend.
What I’ve tried so far
In my function I’ve tried populating the following custom metadata within each product:
_yoast_wpseo_metadesc
_yoast_wpseo_title
_yoast_wpseo_primary_product_cat
_yoast_wpseo_content_score
_yoast_wpseo_estimated-reading-time-minutes
But unfortunately setting all of the above doesn’t seem to affect the display of the breadcrumbs.
I’ve also tried clearing product transients in wp-admin after import and product creation but this didn’t resolve the issue.
Any ideas on how I can get this working? Is there a function I can run as part of the WC-Product object which will trigger the breadcrumbs to sort themselves out as it does when manually clicking Update in edit product?
Any help would be greatly appreciated
2
Answers
Just in case it helps anyone else in the future having the same issue, the problem was due to my code, which modified the category and Yoast primary category after the last execution of wp_update_post.
Simply running wp_update_post( $product_id ) after programmatically updating the category / primary category fixed the malformed breadcrumb issue.
Well it really depends how you’re importing products. Currently, when each product insert, SEO Yoast meta isn’t setting up in database so everytime you need to edit and update that product.
The custom meta might also not worked in your case because you’re not inserting data in other Yoast table like
_yoast_indexable
.Can you show us how you’re importing products so we might help you?