Example #1
0
 /**
  * Construct object.
  */
 public function __construct()
 {
     // Shipping Class translation is not supported after WooCommerce 2.6
     // Note: WooCommerce change the Shipping Class interface and is no longer
     // using the same actions and filters as WordPress. Therefore Polylang
     // can't display the languages columns and metabox for custom post types
     // and taxonomies.
     if (Utilities::woocommerceVersionCheck('2.6')) {
         // Force shipping class translation feature to off
         if ('off' !== Settings::getOption('shipping-class', Features::getID())) {
             $settings = get_option(Features::getID());
             $settings['shipping-class'] = 'off';
             update_option(Features::getID(), $settings);
         }
         // Disable shipping class translation feature input selector
         add_action('current_screen', array($this, 'disableSettings'));
     }
     // Register woocommerce shipping method custom names in polylang strings translations table
     // called only after Wordpress is loaded
     add_action('wp_loaded', array($this, 'registerShippingStringsForTranslation'));
     // Shipping method in the Cart and Checkout pages
     add_filter('woocommerce_shipping_rate_label', array($this, 'translateShippingLabel'), 10, 1);
     // Shipping method in My Account page, Order Emails and Paypal requests
     add_filter('woocommerce_order_shipping_method', array($this, 'translateOrderShippingMethod'), 10, 2);
 }
 /**
  * Construct object
  */
 public function __construct()
 {
     // manage product translation
     add_filter('pll_get_post_types', array($this, 'manageProductTranslation'));
     // sync post parent (good for grouped products)
     add_filter('admin_init', array($this, 'syncPostParent'));
     new Meta();
     new Variable();
     new Duplicator();
     if ('on' === Settings::getOption('stock', Features::getID(), 'on')) {
         new Stock();
     }
 }
 /**
  * Get managed taxonomies
  *
  * @return array taxonomies that must be added and removed to polylang
  */
 protected function prepareAndGet()
 {
     $add = array();
     $remove = array();
     $supported = array('attributes' => 'Hyyan\\WPI\\Taxonomies\\Attributes', 'categories' => 'Hyyan\\WPI\\Taxonomies\\Categories', 'tags' => 'Hyyan\\WPI\\Taxonomies\\Tags', 'shipping-class' => 'Hyyan\\WPI\\Taxonomies\\ShippingCalss');
     foreach ($supported as $option => $class) {
         $names = $class::getNames();
         if ('on' === Settings::getOption($option, Features::getID(), 'on')) {
             $add = array_merge($add, $names);
             if (!isset($this->managed[$class])) {
                 $this->managed[$class] = new $class();
             }
         } else {
             $remove = array_merge($remove, $names);
         }
     }
     return array($add, $remove);
 }
Example #4
0
 /**
  * Download Translation
  *
  * Download woocommerce translation when polylang add new langauge
  *
  * @return boolean true if action executed successfully , false otherwise
  */
 public function downlaodWhenPolylangAddLangauge()
 {
     if ('off' === Settings::getOption('language-downloader', Features::getID(), 'on')) {
         return false;
     }
     if (!isset($_REQUEST['pll_action']) || 'add' !== esc_attr($_REQUEST['pll_action'])) {
         return false;
     }
     $name = esc_attr($_REQUEST['name']);
     $locale = esc_attr($_REQUEST['locale']);
     if ('en_us' === strtolower($locale)) {
         return true;
     }
     try {
         return TranslationsDownloader::download($locale, $name);
     } catch (\RuntimeException $ex) {
         add_settings_error('general', $ex->getCode(), $ex->getMessage());
         return false;
     }
 }
 /**
  * Construct object
  */
 public function __construct()
 {
     $this->tab = isset($_GET['tab']) ? esc_attr($_GET['tab']) : false;
     $this->report = isset($_GET['report']) ? esc_attr($_GET['report']) : false;
     if ('off' === Settings::getOption('reports', Features::getID(), 'on')) {
         return;
     }
     /* Handle products filtering and combining */
     if ('orders' == $this->tab || false === $this->report) {
         add_filter('woocommerce_reports_get_order_report_data', array($this, 'combineProductsByLanguage'));
         add_filter('woocommerce_reports_get_order_report_query', array($this, 'filterProductByLanguage'));
     }
     /* handle stock table filtering */
     add_filter('woocommerce_report_most_stocked_query_from', array($this, 'filterStockByLangauge'));
     add_filter('woocommerce_report_out_of_stock_query_from', array($this, 'filterStockByLangauge'));
     add_filter('woocommerce_report_low_in_stock_query_from', array($this, 'filterStockByLangauge'));
     /* Combine product report with its translation */
     add_action('admin_init', array($this, 'translateProductIDS'));
     /* Combine product category report with its translation */
     add_action('admin_init', array($this, 'translateCategoryIDS'));
     add_filter('woocommerce_report_sales_by_category_get_products_in_category', array($this, 'addProductsInCategoryTranslations'), 10, 2);
 }
Example #6
0
 /**
  * Construct object.
  */
 public function __construct()
 {
     if ('on' === Settings::getOption('emails', Features::getID(), 'on')) {
         add_filter('plugin_locale', array($this, 'correctLocal'), 100);
         // Register woocommerce email subjects and headings in polylang strings translations table
         $this->registerEmailStringsForTranslation();
         // called only after all plugins are loaded
         // Translate Woocommerce email subjects and headings to the order language
         // new order
         add_filter('woocommerce_email_subject_new_order', array($this, 'translateEmailSubjectNewOrder'), 10, 2);
         add_filter('woocommerce_email_heading_new_order', array($this, 'translateEmailHeadingNewOrder'), 10, 2);
         // processing order
         add_filter('woocommerce_email_subject_customer_processing_order', array($this, 'translateEmailSubjectCustomerProcessingOrder'), 10, 2);
         add_filter('woocommerce_email_heading_customer_processing_order', array($this, 'translateEmailHeadingCustomerProcessingOrder'), 10, 2);
         // refunded order
         add_filter('woocommerce_email_subject_customer_refunded_order', array($this, 'translateEmailSubjectCustomerRefundedOrder'), 10, 2);
         add_filter('woocommerce_email_heading_customer_refunded_order', array($this, 'translateEmailHeadingCustomerRefundedOrder'), 10, 2);
         // customer note
         add_filter('woocommerce_email_subject_customer_note', array($this, 'translateEmailSubjectCustomerNote'), 10, 2);
         add_filter('woocommerce_email_heading_customer_note', array($this, 'translateEmailHeadingCustomerNote'), 10, 2);
         // customer invoice
         add_filter('woocommerce_email_subject_customer_invoice', array($this, 'translateEmailSubjectCustomerInvoice'), 10, 2);
         add_filter('woocommerce_email_heading_customer_invoice', array($this, 'translateEmailHeadingCustomerInvoice'), 10, 2);
         // customer invoice paid
         add_filter('woocommerce_email_subject_customer_invoice_paid', array($this, 'translateEmailSubjectCustomerInvoicePaid'), 10, 2);
         add_filter('woocommerce_email_heading_customer_invoice_paid', array($this, 'translateEmailHeadingCustomerInvoicePaid'), 10, 2);
         // completed order
         add_filter('woocommerce_email_subject_customer_completed_order', array($this, 'translateEmailSubjectCustomerCompletedOrder'), 10, 2);
         add_filter('woocommerce_email_heading_customer_completed_order', array($this, 'translateEmailHeadingCustomerCompletedOrder'), 10, 2);
         // new account
         add_filter('woocommerce_email_subject_customer_new_account', array($this, 'translateEmailSubjectCustomerNewAccount'), 10, 2);
         add_filter('woocommerce_email_heading_customer_new_account', array($this, 'translateEmailHeadingCustomerNewAccount'), 10, 2);
         // reset password
         add_filter('woocommerce_email_subject_customer_reset_password', array($this, 'translateEmailSubjectCustomerResetPassword'), 10, 2);
         add_filter('woocommerce_email_heading_customer_reset_password', array($this, 'translateEmailHeadingCustomerResetPassword'), 10, 2);
     }
 }
Example #7
0
 /**
  * Add the Fields Locker script
  *
  * The script will disable editing of some porduct metas for product
  * translation
  *
  * @return boolean false if the fields locker feature is disabled
  */
 public function addFieldsLocker()
 {
     if ('off' === Settings::getOption('fields-locker', \Hyyan\WPI\Admin\Features::getID(), 'on')) {
         return false;
     }
     $metas = static::getProductMetaToCopy();
     $selectors = apply_filters(HooksInterface::FIELDS_LOCKER_SELECTORS_FILTER, array('.insert', in_array('_product_attributes', $metas) ? '#product_attributes :input' : rand()));
     $jsID = 'product-fields-locker';
     $code = sprintf('var disabled = %s;' . 'for (var i = 0; i < disabled.length; i++) {' . ' $(' . '     %s + ","' . '     + "." + disabled[i] + ","' . '     + "#" +disabled[i] + ","' . '     + "*[name^=\'"+disabled[i]+"\']"' . ' )' . '     .off("click")' . '     .on("click", function (e) {e.preventDefault()})' . '     .css({' . '         opacity: .5,' . '         \'pointer-events\': \'none\',' . '         cursor: \'not-allowed\'' . '     }' . ' );' . '}', json_encode($metas), !empty($selectors) ? json_encode(implode(',', $selectors)) : array(rand()));
     Utilities::jsScriptWrapper($jsID, $code);
 }
Example #8
0
 /**
  * Construct object.
  */
 public function __construct()
 {
     if ('on' === Settings::getOption('coupons', Features::getID(), 'on')) {
         add_action('woocommerce_coupon_loaded', array($this, 'couponLoaded'));
     }
 }
 /**
  * Construct object
  */
 public function __construct()
 {
     if ('on' === Settings::getOption('emails', Features::getID(), 'on')) {
         add_filter('plugin_locale', array($this, 'correctLocal'), 100);
     }
 }
Example #10
0
 /**
  * Get managed taxonomies
  *
  * @return array taxonomies that must be added and removed to polylang
  */
 protected function prepareAndGet()
 {
     $add = array();
     $remove = array();
     $supported = array('attributes' => 'Hyyan\\WPI\\Taxonomies\\Attributes', 'categories' => 'Hyyan\\WPI\\Taxonomies\\Categories', 'tags' => 'Hyyan\\WPI\\Taxonomies\\Tags', 'shipping-class' => 'Hyyan\\WPI\\Taxonomies\\ShippingClass');
     // and will be removed from the taxomonies to be filteres by language, because Shipping Classes can no longer
     // be translated in Polylang
     foreach ($supported as $option => $class) {
         $names = $class::getNames();
         if ('on' === Settings::getOption($option, Features::getID(), 'on')) {
             $add = array_merge($add, $names);
             if (!isset($this->managed[$class])) {
                 $this->managed[$class] = new $class();
             }
         } else {
             $remove = array_merge($remove, $names);
         }
     }
     return array($add, $remove);
 }