コード例 #1
0
ファイル: Meta.php プロジェクト: qRoC/woo-poly-integration
 /**
  * Define the meta keys that must copyied from orginal product to its
  * translation
  *
  * @param array   $metas array of meta keys
  * @param boolean $flat  false to return meta list with sections (default true)
  *
  * @return array extended meta keys array
  */
 public static function getProductMetaToCopy(array $metas = array(), $flat = true)
 {
     $default = apply_filters(HooksInterface::PRODUCT_META_SYNC_FILTER, array('general' => array('name' => __('General Metas', 'woo-poly-integration'), 'desc' => __('General Metas', 'woo-poly-integration'), 'metas' => array('product-type', '_virtual', '_downloadable', '_sku', '_regular_price', '_sale_price', '_sale_price_dates_from', '_sale_price_dates_to', '_downloadable_files', '_download_limit', '_download_expiry', '_download_type', 'menu_order', 'comment_status', '_upsell_ids', '_crosssell_ids', '_featured', '_thumbnail_id', '_price', '_product_image_gallery', 'total_sales', '_translation_porduct_type', '_visibility')), 'stock' => array('name' => __('Stock Metas', 'woo-poly-integration'), 'desc' => __('Stock Metas', 'woo-poly-integration'), 'metas' => array('_manage_stock', '_stock', '_backorders', '_stock_status', '_sold_individually')), 'shipping' => array('name' => __('ShippingClass Metas', 'woo-poly-integration'), 'desc' => __('ShippingClass Metas', 'woo-poly-integration'), 'metas' => array('_weight', '_length', '_width', '_height', 'product_shipping_class')), 'Attributes' => array('name' => __('Attributes Metas', 'woo-poly-integration'), 'desc' => __('Attributes Metas', 'woo-poly-integration'), 'metas' => array('_product_attributes', '_default_attributes')), 'Taxes' => array('name' => __('Taxes Metas', 'woo-poly-integration'), 'desc' => __('Taxes Metas', 'woo-poly-integration'), 'metas' => array('_tax_status', '_tax_class'))));
     if (false === $flat) {
         return $default;
     }
     foreach ($default as $ID => $value) {
         $metas = array_merge($metas, Settings::getOption($ID, MetasList::getID(), $value['metas']));
     }
     return array_values($metas);
 }
コード例 #2
0
ファイル: Stock.php プロジェクト: hyyan/woo-poly-integration
 /**
  * Change the product stock in the given order item.
  *
  * @param array  $item   the order data
  * @param string $action STOCK_REDUCE_ACTION | STOCK_INCREASE_ACTION
  */
 protected function change(array $item, $action = self::STOCK_REDUCE_ACTION)
 {
     $productID = $item['product_id'];
     $productObject = wc_get_product($productID);
     $productLang = pll_get_post_language($productID);
     $variationID = $item['variation_id'];
     /* Handle Products */
     if ($productObject && $productLang) {
         /* Get the translations IDS */
         $translations = Utilities::getProductTranslationsArrayByObject($productObject);
         /* Remove the current product from translation array */
         unset($translations[$productLang]);
         $isManageStock = $productObject->managing_stock();
         $isVariation = $variationID && $variationID > 0;
         $method = $action === self::STOCK_REDUCE_ACTION ? 'reduce_stock' : 'increase_stock';
         $change = $action === self::STOCK_REDUCE_ACTION ? $item['qty'] : $item['change'];
         /* Sync stock for all translation */
         foreach ($translations as $ID) {
             /* Only if product is managing stock */
             if ($isManageStock) {
                 if ($translation = wc_get_product($ID)) {
                     $translation->{$method}($change);
                 }
             }
             $general = Settings::getOption('general', MetasList::getID(), array('total_sales'));
             if (in_array('total_sales', $general)) {
                 update_post_meta($ID, 'total_sales', get_post_meta($productID, 'total_sales', true));
             }
         }
         /* Handle variation */
         if ($isVariation) {
             $posts = Variation::getRelatedVariation($variationID);
             foreach ($posts as $post) {
                 if ($post->ID == $variationID) {
                     continue;
                 }
                 $variation = wc_get_product($post);
                 if ($variation && $variation->managing_stock()) {
                     $variation->{$method}($change);
                 }
             }
         }
     }
 }