This code solved my problem
function ai_seo_change_canonical($canonical)
{
global $product;
if(is_product() && !empty($_GET)) {
$variationID = (new \WC_Product_Data_Store_CPT())->find_matching_product_variation(
new \WC_Product($product->get_id()),
$_GET
);
if($variationID) {
$variation = wc_get_product($variationID);
if($variation) {
$canonical = $variation->get_permalink();
}
}
}
return $canonical;
}
add_filter('wpseo_canonical','ai_seo_change_canonical');
-
This reply was modified 1 year, 3 months ago by Alan.