/** * Add the disable Shipping Class translation feature script. * * The script will disable enabling the Shipping Class translation feature */ public function disableShippingClassFeature() { $jsID = 'shipping-class-translation-disabled'; $code = '$( "#wpuf-wpi-features\\\\[shipping-class\\\\]" ).prop( "disabled", true );'; // To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) // as a literal part of a name, it must be escaped with with two backslashes: \\. // Because jsScriptWrapper() uses sprintf() it will treat one backslash as escape // character, so we need to add a 3rd (crazy!) backslashes. Utilities::jsScriptWrapper($jsID, $code); }
/** * Sync the product type selection (e.g. Simple product, Grouped product, Variable * product, etc ) in the dropdown list in the Product Data settings box * * @param integer $ID Product Id */ protected function sync_product_type_selection($ID = null) { /* * First we add save_post action to save the product type * as post meta * * This is step is important so we can get the right product type */ add_action('save_post', function ($_ID) { $product = wc_get_product($_ID); if ($product && !isset($_GET['from_post'])) { update_post_meta($_ID, '_translation_porduct_type', $product->product_type); } }); /* * If the _translation_porduct_type meta is found then we add the * js script to sync the product type selection * * TODO: Change the product type in the DB instead with * wp_set_object_terms( $product_id, 'the new product type', 'product_type' ); * */ if ($ID && ($type = get_post_meta($ID, '_translation_porduct_type'))) { add_action('admin_print_scripts', function () use($type) { $jsID = 'product-type-sync'; $code = sprintf('// <![CDATA[ %1$s' . ' addLoadEvent(function () { %1$s' . ' jQuery("#product-type option")' . ' .removeAttr("selected");%1$s' . ' jQuery("#product-type option[value=\\"%2$s\\"]")' . ' .attr("selected", "selected");%1$s' . '})' . '// ]]>', PHP_EOL, $type[0]); Utilities::jsScriptWrapper($jsID, $code, false); }, 11); } }
/** * Add a button before the attributes table to let the user know how to * translate the attributes labels * * @global type $pagenow * * @return boolean false if not attributes page */ public function addAttrsTranslateLinks() { global $pagenow; if ($pagenow !== 'edit.php') { return false; } $isAttrPage = isset($_GET['page']) && esc_attr($_GET['page']) === 'product_attributes'; if (!$isAttrPage) { return false; } $stringTranslationURL = add_query_arg(array('page' => 'mlang', 'tab' => 'strings', 'group' => __('Woocommerce Attributes', 'woo-poly-integration')), admin_url('options-general.php')); /* Add attribute translate button */ $buttonID = 'attrs-label-translation-button'; $buttonCode = sprintf('$("<a href=\'%s\' class=\'button button-primary button-large\'>%s</a><br><br>")' . ' .insertBefore(".attributes-table");', $stringTranslationURL, __('Translate Attributes Lables', 'woo-poly-integration')); /* Add attribute translate search link */ $searchLinkID = 'attr-label-translate-search-link'; $searchLinkCode = sprintf("\$('.attributes-table .row-actions').each(function () {\n" . ' var $this = $(this);' . ' var attrName = $this.parent().find("strong a").text();' . ' var attrTranslateUrl = "%s&s="+attrName ;' . ' var attrTranslateHref = ' . ' "<span class=\'translate\'>"' . ' + "| "' . ' + "<a href=\'"+attrTranslateUrl+"\'>%s</a>"' . ' + "</span>";' . ' $this.append(attrTranslateHref);' . "\n});\n", $stringTranslationURL, __('Translate', 'woo-poly-integration')); /* Output code */ Utilities::jsScriptWrapper($buttonID, $buttonCode); Utilities::jsScriptWrapper($searchLinkID, $searchLinkCode); }
/** * Check if we have to disable the language switcher in the polylang setting * page */ public function shouldDisableLangSwitcher() { add_action('current_screen', function () { $screen = get_current_screen(); if ($screen->id !== 'settings_page_mlang') { return false; } $count = wp_count_posts('product_variation'); if (!($count && $count->publish > 0)) { return false; } add_action('admin_print_scripts', function () { $jsID = 'disable-lang-switcher'; $code = sprintf('$("#options-lang #default_lang")' . '.css({' . ' "opacity": .5,' . ' "pointer-events": "none"' . '});' . ' $("#options-lang").prepend(' . ' "<p class=\'update-nag\'>%s</p>"' . ');', __('You can not change the default language, when adding variable products', 'woopoly')); Utilities::jsScriptWrapper($jsID, $code); }, 100); }); }