Bug Fix: Yoast SEO and Woo Commerce Variation Swatches and Photos

I recently had a client ask me why they weren’t able to upload an image swatch using the Woocommerce variation swatches and photos plugin. Every time they tried to do it the page refreshed. It seemed to me like that the script that gets fired off when clicking the anchor ‘Upload Image’ wasnt firing.

Here is what I found in the Console tool of firebug:

[dt_code]

17:14:14.373 TypeError: document.getElementById(…) is null
g.prototype.getDataFromInput() wp-seo-term-scraper-310.min.js:1
g.prototype.getData() wp-seo-term-scraper-310.min.js:1
b() wp-seo-term-scraper-310.min.js:1
<anonymous> wp-seo-term-scraper-310.min.js:1
m.Callbacks/j() load-scripts.php:2
m.Callbacks/k.fireWith() load-scripts.php:2
.ready() load-scripts.php:2
J() load-scripts.php:2
1 wp-seo-term-scraper-310.min.js:1:1961

[/dt_code]

The problem lies with the wp-seo-term-scraper.js file. It seems like because product attributes dont have any SEO options the js file looks for something that doesn’t exist and blocks up all javascript after that.

The file class-taxonomy.php is where term-scraper is called (enqueued). So what I did was to use a return statement causing none of the woocommerce js to be called. To do this you need to edit line 80 of of class-taxonomy.php so it looks like this:

[dt_code]

$post_type = $_GET[“post_type”];

if ( $GLOBALS[‘pagenow’] !== ‘edit-tags.php’ || $post_type == ‘product’ ) {
return;
}

[/dt_code]

All we are doing is checking to see if the post type is a product and then choosing to exit the sub routine (not proceed with the further lines of code).

This promptly fixed the issue!

 

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top