/** * {@inheritdoc} */ protected function doGetFields() { /* Metas list */ $metas = Meta::getProductMetaToCopy(array(), false); $fields = array(); foreach ($metas as $ID => $value) { $fields[] = array('name' => $ID, 'label' => $value['name'], 'desc' => $value['desc'], 'type' => 'multicheck', 'default' => array_combine($value['metas'], $value['metas']), 'options' => array_combine($value['metas'], array_map(array(__CLASS__, 'normalize'), $value['metas']))); } return $fields; }
/** * Construct object */ public function __construct() { /* Just to prepare taxonomies */ $this->prepareAndGet(); /* List of taxonomies which will be filtered by language */ add_filter('pll_get_taxonomies', array($this, 'manageTaxonomiesTranslation')); if (Utilities::woocommerce_version_check('2.6')) { /* List of taxonomies to be copied/synced with exact same value */ $metas = Meta::getProductMetaToCopy(); // Shipping Class taxonomy translation is not supported after WooCommerce 2.6 if (in_array('product_shipping_class', $metas)) { $this->tax_to_copy[] = 'product_shipping_class'; } add_filter('pll_copy_taxonomies', array($this, 'copy_taxonomies'), 10, 2); } }
/** * Sync default attributes between product translations * * @param int $post_id Post ID * @param \WP_Post $post Post Object * @param boolean $update true if updating the post, false otherwise */ public function sync_default_attributes($post_id, $post, $update) { // Don't sync if not in the admin backend nor on autosave if (!is_admin() && defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // Don't sync if Default Attribute syncronization is disabled $metas = Meta::getProductMetaToCopy(); if (!in_array('_default_attributes', $metas)) { return; } // To avoid Polylang overwriting default attribute meta add_filter('delete_post_metadata', array($this, 'skip_default_attributes_meta'), 10, 4); add_filter('add_post_metadata', array($this, 'skip_default_attributes_meta'), 10, 4); add_filter('update_post_metadata', array($this, 'skip_default_attributes_meta'), 10, 4); // Don't sync if not a Variable Product $product = wc_get_product($post_id); if ($product && 'simple' === $product->product_type && Utilities::maybe_variable_product($product)) { // Maybe is Variable Product // New translations of Variable Products are first created as simple // Only need to sync for the new translation from source product // The other product translation stay untouched $attributes_translation = Utilities::get_default_attributes_translation($_GET['from_post'], $_GET['new_lang']); if (!empty($attributes_translation) && isset($attributes_translation[$_GET['new_lang']])) { update_post_meta($product->id, '_default_attributes', $attributes_translation[$_GET['new_lang']]); } } elseif ($product && 'variable' === $product->product_type) { // Variable Product // For each product translation, get the translated (default) terms/attributes $attributes_translation = Utilities::get_default_attributes_translation($product->id); $langs = pll_languages_list(); foreach ($langs as $lang) { $translation_id = pll_get_post($product->id, $lang); if ($translation_id != $product->id) { update_post_meta($translation_id, '_default_attributes', $attributes_translation[$lang]); } } } }