admin管理员组文章数量:1302929
I would like to rewrite SKUs generated by WooCommerce Product SKU Generator and prefix them with the vendor slug from WooCommerce Product Vendors into the following format: [Vendor Slug][Generated SKU]. E.g. 'GT1234', 'JD1235', etc... If the product author is not a vendor or the order is not associated with a vendor, the prefix should default to 'XX'.
Main difficulty for me is retrieving the vendor slug for the user adding the new product. How would I go about doing that? Anything to get me going is appreciated!
function filter_wc_sku_generator_sku( $product_sku, $product ) {
$vendor_slug = '???'
if (!$vendor_slug) {
$product_sku = 'XX' . $product_sku;
} else {
$product_sku = $vendor_slug . $product_sku;
}
return $product_sku;
};
add_filter( 'wc_sku_generator_sku', 'filter_wc_sku_generator_sku', 10, 2 );
I would like to rewrite SKUs generated by WooCommerce Product SKU Generator and prefix them with the vendor slug from WooCommerce Product Vendors into the following format: [Vendor Slug][Generated SKU]. E.g. 'GT1234', 'JD1235', etc... If the product author is not a vendor or the order is not associated with a vendor, the prefix should default to 'XX'.
Main difficulty for me is retrieving the vendor slug for the user adding the new product. How would I go about doing that? Anything to get me going is appreciated!
function filter_wc_sku_generator_sku( $product_sku, $product ) {
$vendor_slug = '???'
if (!$vendor_slug) {
$product_sku = 'XX' . $product_sku;
} else {
$product_sku = $vendor_slug . $product_sku;
}
return $product_sku;
};
add_filter( 'wc_sku_generator_sku', 'filter_wc_sku_generator_sku', 10, 2 );
Share
Improve this question
asked Jan 7, 2019 at 0:59
Gion TummersGion Tummers
31 bronze badge
1
- What code did you finally use to include the seller's initials in the plugin auto-generated SKU? Thanks – Alvaro Commented Feb 17, 2021 at 20:27
1 Answer
Reset to default 0There's a class WC_Product_Vendors_Utils
that you can use e.g.
$vendor = WC_Product_Vendors_Utils::is_vendor_product( $item["product_vendors_product_id"] ); //replace this with the product ID
if ( ! empty( $vendor[0] ) ) {
$vendor_data = WC_Product_Vendors_Utils::get_vendor_data_by_id( $vendor[0]->term_id );
if ( ! empty( $vendor_data ) ) {
$vendor_slug = $vendor_data['slug']; // I am not sure of the correct value here but you can var_dump() just to make sure
}
}
Hope that will help you start generating the SKU properly :)
本文标签: pluginsAdd WooCommerce vendor slug to autogenerated SKU
版权声明:本文标题:plugins - Add WooCommerce vendor slug to auto-generated SKU 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741742636a2395352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论