Skip to content

Instantly share code, notes, and snippets.

@InpsydeNiklas
Last active November 3, 2022 17:56
Show Gist options
  • Save InpsydeNiklas/18ea39130b1e02af5b7d16b7e57af47f to your computer and use it in GitHub Desktop.
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)
<?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