我没有在电子邮件上尝试过,但这适用于仪表板区域和前端..
add_filter( 'woocommerce_get_sku', 'reigel_woocommerce_get_sku', 10, 2 );
function reigel_woocommerce_get_sku( $sku, $product ){
// remove current filter to prevent unli loop on get_sku()
remove_filter( current_filter(), __FUNCTION__ );
if ( $product->get_type() === 'variation' ) {
$parent = $product->parent->id?$product->parent->id:$product->get_parent();
$sku = wc_get_product($parent)->get_sku() . '/' . $sku;
}
add_filter( 'woocommerce_get_sku', 'reigel_woocommerce_get_sku', 10, 2 );
return $sku;
}
在变体上禁用 sku 唯一性...
add_filter( 'wc_product_has_unique_sku', 'reigel_wc_product_has_unique_sku', 10, 3 );
function reigel_wc_product_has_unique_sku( $sku_found, $product_id, $sku ) {
$product = wc_get_product($product_id);
if ( $product->get_type() === 'variation' ) {
$sku_found = false;
}
return $sku_found;
}