I am trying to do a reverse lookup to get the Permalink to a product from its SKU. The output of which will be used to redirect old URLS to new ones.

I am having trouble understanding the relationships between the tables used in woocommerce. The products seem to be stored in wp\_posts, and the SKU in wp\_wc\_product\_meta\_lookup however when creating a join in the database tables this does not bring up the expected data :

```
SELECT pml.sku,pml.product_id,wpp.guid FROM wp_wc_product_meta_lookup pml LEFT JOIN wp_posts wpp ON wpp.ID=pml.product_id WHERE pml.stock_status='instock'

```

In addition to this the guid in wp\_posts is not the same as the actual product URL - the categories are different.

Thanks,

Rick