Created
September 17, 2025 13:49
-
-
Save mehrshaddarzi/76d3f601b211bf0065d5df2754af10c9 to your computer and use it in GitHub Desktop.
wc-multisite use custom meta as sku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter('wc_multisite_prepare_variation_product_item_data', function($data, $variation) { | |
| $meta = get_post_meta($variation->get_id(), 'mahak_product_detail_id', true); | |
| if(empty($meta)) { | |
| return $data; | |
| } | |
| $sku = $variation->get_sku(); | |
| $parent_id = $variation->get_parent_id(); | |
| if ($parent_id > 0) { | |
| $parent_product = wc_get_product($parent_id); | |
| if ($parent_product and $sku == $parent_product->get_sku()) { | |
| $data['sku'] = $meta; | |
| } | |
| } | |
| return $data; | |
| }, 20, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment