Last active
November 3, 2022 17:56
-
-
Save InpsydeNiklas/18ea39130b1e02af5b7d16b7e57af47f to your computer and use it in GitHub Desktop.
MultilingualPress - Copy SKU & Price to Product Data tab in the metabox for the remote product(s)
This file contains 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 | |
use Inpsyde\MultilingualPress\TranslationUi\Post\RelationshipContext; | |
add_action('multilingualpress.metabox_after_update_remote_product', | |
static function(RelationshipContext $context, WC_Product $remoteProduct, WC_Product $sourceProduct) { | |
$remoteSku = $remoteProduct->get_sku() ?? ''; | |
$remotePrice = $remoteProduct->get_price() ?? ''; | |
if (!empty($remoteSku) && !empty($remotePrice)) { | |
return; | |
} | |
$sourceSiteId = $context->sourceSiteId(); | |
switch_to_blog($sourceSiteId); | |
$sourceSku = $sourceProduct->get_sku() ?? ''; | |
$sourcePrice = $sourceProduct->get_price() ?? ''; | |
restore_current_blog(); | |
$remoteProduct->set_price($sourcePrice); | |
$remoteProduct->set_sku($sourceSku); | |
}, | |
10, | |
4 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment