Exemplo n.º 1
0
 /**
  * Sync product meta.
  *
  * @return false if the current post type is not "product"
  */
 public function syncProductsMeta()
 {
     // sync product meta with polylang
     add_filter('pll_copy_post_metas', array(__CLASS__, 'getProductMetaToCopy'));
     // Shipping Class translation is not supported after WooCommerce 2.6 but it is
     // still implemented by WooCommerce as a taxonomy. Therefore Polylang will not
     // copy the Shipping Class meta. We need to take care of it.
     if (Utilities::woocommerceVersionCheck('2.6')) {
         add_action('wp_insert_post', array($this, 'syncShippingClass'), 10, 3);
     }
     $currentScreen = get_current_screen();
     if ($currentScreen->post_type !== 'product') {
         return false;
     }
     $ID = false;
     $disable = false;
     /*
      * Disable editing product meta for translation
      *
      * if the "post" is defined in $_GET then we should check if the current
      * product has a translation and it is the same as the default translation
      * lang defined in polylang then product meta editing must by enabled
      *
      * if the "new_lang" is defined or if the current page is the "edit"
      * page then product meta editing must by disabled
      */
     if (isset($_GET['post'])) {
         $ID = absint($_GET['post']);
         $disable = $ID && pll_get_post_language($ID) != pll_default_language();
     } elseif (isset($_GET['new_lang']) || $currentScreen->base == 'edit') {
         $disable = isset($_GET['new_lang']) && esc_attr($_GET['new_lang']) != pll_default_language() ? true : false;
         $ID = isset($_GET['from_post']) ? absint($_GET['from_post']) : false;
         // Add the '_translation_porduct_type' meta, for the case where
         // the product was created before plugin acivation.
         $this->addProductTypeMeta($ID);
     }
     // disable fields edit for translation
     if ($disable) {
         add_action('admin_print_scripts', array($this, 'addFieldsLocker'), 100);
     }
     /* sync selected product type */
     $this->syncSelectedproductType($ID);
 }
Exemplo n.º 2
0
 /**
  * Helper function - Gets the shipping methods enabled in the shop.
  *
  * @return array $active_methods The id and respective plugin id of all active methods
  */
 private function getActiveShippingMethods()
 {
     $active_methods = array();
     if (Utilities::woocommerceVersionCheck('2.6')) {
         //  WooCommerce 2.6 intoduces the concept of Shipping Zones
         // Format:  $shipping_methods[zone_name_method_id] => shipping_method_object
         // where zone_name is e.g. domestic, europe, rest_of_the_world, and
         // methods_id is e.g. flat_rate, free_shiping, local_pickup, etc
         $shipping_methods = $this->getZonesShippingMethods();
     } else {
         // Format:  $shipping_methods[method_id] => shipping_method_object
         // where methods_id is e.g. flat_rate, free_shiping, local_pickup, etc
         $shipping_methods = WC()->shipping->load_shipping_methods();
     }
     foreach ($shipping_methods as $id => $shipping_method) {
         if (isset($shipping_method->enabled) && 'yes' === $shipping_method->enabled) {
             $active_methods[$id] = $shipping_method->plugin_id;
         }
     }
     return $active_methods;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function doGetFields()
 {
     return array(array('name' => 'fields-locker', 'type' => 'checkbox', 'default' => 'on', 'label' => __('Fields Locker', 'woo-poly-integration'), 'desc' => __('Fields locker makes it easy for user to know which
                      field to translate and which to ignore ', 'woo-poly-integration')), array('name' => 'emails', 'type' => 'checkbox', 'default' => 'on', 'label' => __('Emails', 'woo-poly-integration'), 'desc' => __('Use order language whenever woocommerce sends order emails', 'woo-poly-integration')), array('name' => 'reports', 'type' => 'checkbox', 'default' => 'on', 'label' => __('Reports', 'woo-poly-integration'), 'desc' => __('Enable reports language filtering and combining', 'woo-poly-integration')), array('name' => 'coupons', 'type' => 'checkbox', 'default' => 'on', 'label' => __('Coupons Sync', 'woo-poly-integration'), 'desc' => __('Apply coupons rules for product and its translations', 'woo-poly-integration')), array('name' => 'stock', 'type' => 'checkbox', 'default' => 'on', 'label' => __('Stock Sync', 'woo-poly-integration'), 'desc' => __('Sync stock for product and its translations', 'woo-poly-integration')), array('name' => 'categories', 'type' => 'checkbox', 'default' => 'on', 'label' => __('Translate Categories', 'woo-poly-integration'), 'desc' => __('Enable categories translations', 'woo-poly-integration')), array('name' => 'tags', 'type' => 'checkbox', 'default' => 'on', 'label' => __('Translate Tags', 'woo-poly-integration'), 'desc' => __('Enable tags translations', 'woo-poly-integration')), array('name' => 'attributes', 'type' => 'checkbox', 'default' => 'on', 'label' => __('Translate Attributes', 'woo-poly-integration'), 'desc' => __('Enable attributes translations', 'woo-poly-integration')), array('name' => 'shipping-class', 'type' => 'checkbox', 'default' => 'off', 'label' => __('Translate Shipping Classes', 'woo-poly-integration'), 'desc' => __('Enable shipping classes translations' . (Utilities::woocommerceVersionCheck('2.6') ? ' (not supported for WooCommerce versions >= 2.6)' : ''), 'woo-poly-integration')));
 }