Can’t save translation
-
Hello,
After editting I cannot save translation.
Cannot find save button and error message comes out.Thanks a lot!
ps: flatsome theme
PHP 7.3, Ubuntu 16.04 all are updated.- This topic was modified 4 years, 1 month ago by aowisdom50.
The page I need help with: [log in to see the link]
-
Please install and enable the plugin “Enable jQuery Migrate Helper”, or apply the following patch:
[Transposh jQuery patch for WordPress 5.5.x]
Transposh uses the live method, which is obsolete in jQuery version 1.9.
/wp-content/plugins/transposh-translation-filter-for-wordpress/js/admin/contexthelp.js:
!function(l){l(“.tp_help”).live(“click”,function(e){e.preventDefault(),window.scrollTo(0,0),l(“#tab-link-“+jQuery(this).attr(“rel”)+” a”).trigger(“click”),l(“#contextual-help-link”).hasClass(“screen-meta-active”)||l(“#contextual-help-link”).trigger(“click”)})}(jQuery);
//# sourceMappingURL=contexthelp.js.map↓
!function(l){l(document).on(“click”,”.tp_help”,function(e){e.preventDefault(),window.scrollTo(0,0),l(“#tab-link-“+jQuery(this).attr(“rel”)+” a”).trigger(“click”),l(“#contextual-help-link”).hasClass(“screen-meta-active”)||l(“#contextual-help-link”).trigger(“click”)})}(jQuery);
//# sourceMappingURL=contexthelp.js.mapFor other plugin fixes, please refer to my blog below:
Thank you for quick reply.
I installed the plugin and activated but this time I can’t edit as edit buttons are not appearing.The latest version of Transposh is 1.0.6.1.
If you install it from WordPress, it is an old version, but after a while, you will receive an update notification, so if you update it, you can use the full functionality.
You can also install the latest version from the following.I already have updated to the latest version.
And I got this notice. ;Previously logged deprecation notices
The following are deprecations logged from the front-end of your site, or while the deprecation box was disabled.
Time Notice Page
2020-10-16 14:26:54 https://www.housezille.com/wp-content/plugins/transposh-translation-filter-for-wordpress/js/admin/contexthelp.js:1:28: jQuery.fn.live() is deprecated https://www.housezille.com/wp-admin/admin.php?page=tp_main- This reply was modified 4 years, 1 month ago by aowisdom50.
The above error disappears after a day after applying the patch to contexthelp.js I have shown.
By the way, “Enable jQuery Migrate Helper” doesn’t work on WordPress 5.7 or later, so you need to fix jQuery of the old interface.
- This reply was modified 4 years, 1 month ago by Senri Miura.
Thanks a lot!
Now edit buttons appear but still I can’t save translated language.
The error message saying: Server’s message: Internal Server Error.- This reply was modified 4 years, 1 month ago by aowisdom50.
What is the PHP version?
PHP 7.3.23-2
ubuntu 16.04.1You should put WordPress in debug mode and parse the execution log.
debug_log;
[18-Oct-2020 09:20:18 UTC] PHP Deprecated: Non-static method WMAMC_wc_cartLimit::WMAMC_instance() should not be called statically in /var/www/wordpress/wp-content/plugins/woo-cart-limit/woocommerce_limit_cart.php on line 1243
[18-Oct-2020 09:20:18 UTC] PHP Notice: Undefined index: HTTP_REFERER in /var/www/wordpress/wp-content/plugins/transposh-translation-filter-for-wordpress/wp/transposh_3rdparty.php on line 307
———————————————————————-transposh_3party.php
<?php
/*
* Transposh v1.0.6.1
* https://transposh.org/
*
* Copyright 2020, Team Transposh
* Licensed under the GPL Version 2 or higher.
* https://transposh.org/license
*
* Date: Wed, 01 Jan 2020 13:14:30 +0200
*//*
* This file handles functions relevant to specific third party plugins
*/class transposh_3rdparty {
/** @var transposh_plugin Container class */
private $transposh;/**
* Construct our class
* @param transposh_plugin $transposh
*/
function __construct(&$transposh) {
$this->transposh = &$transposh;// supercache invalidation of pages – first lets find if supercache is here
if (function_exists(‘wp_super_cache_init’)) {
add_action(‘transposh_translation_posted’, array(&$this, ‘super_cache_invalidate’));
}// W3TC cache invalitadion
if (function_exists(‘w3tc_pgcache_flush_post’)) {
add_action(‘transposh_translation_posted’, array(&$this, ‘w3tc_invalidate’));
}// buddypress compatability
add_filter(‘bp_uri’, array(&$this, ‘bp_uri_filter’));
add_filter(‘bbp_get_search_results_url’, array(&$this, ‘bbp_get_search_results_url’));
add_filter(‘bp_get_activity_content_body’, array(&$this, ‘bp_get_activity_content_body’), 10, 2);
add_action(‘bp_activity_after_save’, array(&$this, ‘bp_activity_after_save’));
add_action(‘transposh_human_translation’, array(&$this, ‘transposh_buddypress_stream’), 10, 3);
//bp_activity_permalink_redirect_url (can fit here if generic setting fails)
// google xml sitemaps – with patch
add_action(‘sm_addurl’, array(&$this, ‘add_sm_transposh_urls’));
// yoast – need patch
add_filter(‘wpseo_sitemap_language’, array(&$this, ‘add_yoast_transposh_urls’));// business directory plugin
add_filter(‘wpbdp_get_page_link’, array(&$this, ‘fix_wpbdp_links_base’));
add_filter(‘wpbdp_listing_link’, array(&$this, ‘fix_wpbdp_links’));
add_filter(‘wpbdp_category_link’, array(&$this, ‘fix_wpbdp_links’));// google analyticator
if ($this->transposh->options->transposh_collect_stats) {
add_action(‘google_analyticator_extra_js_after’, array(&$this, ‘add_analyticator_tracking’));
}// woocommerce
add_filter(‘woocommerce_get_checkout_url’, array(&$this, ‘woo_uri_filter’));
add_filter(‘woocommerce_get_cart_url’, array(&$this, ‘woo_uri_filter’));
}function add_analyticator_tracking() {
echo ” _gaq.push([‘_setAccount’, ‘UA-4663695-5’]);\n”;
echo ” _gaq.push([‘_setDomainName’, ‘none’]);\n”;
echo ” _gaq.push([‘_setAllowLinker’, true]);\n”;
echo ” _gaq.push([‘_trackPageview’]);\n”;
}function super_cache_invalidate() {
//Now, we are actually using the referrer and not the request, with some precautions
$GLOBALS[‘wp_cache_request_uri’] = substr($_SERVER[‘HTTP_REFERER’], stripos($_SERVER[‘HTTP_REFERER’], $_SERVER[‘HTTP_HOST’]) + strlen($_SERVER[”] . $_SERVER[‘HTTP_HOST’]));
$GLOBALS[‘wp_cache_request_uri’] = preg_replace(‘/[ <>\’\”\r\n\t\(\)]/’, ”, str_replace(‘/index.php’, ‘/’, str_replace(‘..’, ”, preg_replace(“/(\?.*)?$/”, ”, $GLOBALS[‘wp_cache_request_uri’]))));
// get some supercache variables
extract(wp_super_cache_init());
tp_logger(wp_super_cache_init());
// this is hackery for logged in users, a cookie is added to the request somehow and gzip is not correctly set, so we forcefully fix this
if (!$cache_file) {
$GLOBALS[‘wp_cache_gzip_encoding’] = gzip_accepted();
unset($_COOKIE[key($_COOKIE)]);
extract(wp_super_cache_init());
tp_logger(wp_super_cache_init());
}$dir = get_current_url_supercache_dir();
// delete possible files that we can figure out, not deleting files for other cookies for example, but will do the trick in most cases
$cache_fname = “{$dir}index.html”;
tp_logger(“attempting delete of supercache: $cache_fname”);
@unlink($cache_fname);
$cache_fname = “{$dir}index.html.gz”;
tp_logger(“attempting delete of supercache: $cache_fname”);
@unlink($cache_fname);
tp_logger(“attempting delete of wp_cache: $cache_file”);
@unlink($cache_file);
tp_logger(“attempting delete of wp_cache_meta: $meta_pathname”);
@unlink($meta_pathname);// go at edit pages too
$GLOBALS[‘wp_cache_request_uri’] .= “?edit=1”;
extract(wp_super_cache_init());
tp_logger(wp_super_cache_init());
tp_logger(“attempting delete of edit_wp_cache: $cache_file”);
@unlink($cache_file);
tp_logger(“attempting delete of edit_wp_cache_meta: $meta_pathname”);
@unlink($meta_pathname);
}function w3tc_invalidate() {
tp_logger(“W3TC invalidate:”.$_SERVER[‘HTTP_REFERER’]);
$id = url_to_postid($_SERVER[‘HTTP_REFERER’]);
if (is_numeric($id)) {
tp_logger(“W3TC invalidate post id: $id”);
w3tc_pgcache_flush_post($id);
} else {
w3tc_pgcache_flush();
}
}/**
* This filter method helps buddypress understand the transposh generated URLs
* @param string $uri The url that was originally received
* @return string The url that buddypress should see
*/
function bp_uri_filter($uri) {
$lang = transposh_utils::get_language_from_url($uri, $this->transposh->home_url);
//TODO – check using get_clean_url
$uri = transposh_utils::cleanup_url($uri, $this->transposh->home_url);
if ($this->transposh->options->enable_url_translate) {
$uri = transposh_utils::get_original_url($uri, ”, $lang, array($this->transposh->database, ‘fetch_original’));
}
return $uri;
}/**
* For search form in current buddypress
* @param type $url
*/
function bbp_get_search_results_url($url) {
$lang = transposh_utils::get_language_from_url($_SERVER[‘HTTP_REFERER’], $this->home_url);
$href = transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, false);
return $href;
}/**
* After saving action, makes sure activity has proper language
* @param BP_Activity_Activity $params
*/
function bp_activity_after_save($params) {
// we don’t need to modify our own activity stream
if ($params->type == ‘new_translation’)
return;
if (transposh_utils::get_language_from_url($_SERVER[‘HTTP_REFERER’], $this->transposh->home_url))
bp_activity_update_meta($params->id, ‘tp_language’, transposh_utils::get_language_from_url($_SERVER[‘HTTP_REFERER’], $this->transposh->home_url));
}/**
* Change the display of activity content using the transposh meta
* @param string $content
* @param BP_Activity_Activity $activity
* @return string modified content
*/
function bp_get_activity_content_body($content, $activity = “”) { //XXX
$activity_lang = bp_activity_get_meta($activity->id, ‘tp_language’);
if ($activity_lang) {
$content = “<span lang =\”$activity_lang\”>” . $content . “</span>”;
}
return $content;
}/**
* Add an item to the activity string upon translation
* @global object $bp the global buddypress
* @param string $translation
* @param string $original
* @param string $lang
*/
function transposh_buddypress_stream($translation, $original, $lang) {
global $bp;// we must have buddypress…
if (!function_exists(‘bp_activity_add’))
return false;// we only log translation for logged on users
if (!$bp->loggedin_user->id)
return;/* Because blog, comment, and blog post code execution happens before anything else
we may need to manually instantiate the activity component globals */
if (!$bp->activity && function_exists(‘bp_activity_setup_globals’))
bp_activity_setup_globals();// just got this from buddypress, changed action and content
$values = array(
‘user_id’ => $bp->loggedin_user->id,
‘action’ => sprintf(__(‘%s translated a phrase to %s with transposh:’, TRANSPOSH_TEXT_DOMAIN), bp_core_get_userlink($bp->loggedin_user->id), substr(transposh_consts::$languages[$lang], 0, strpos(transposh_consts::$languages[$lang], ‘,’))),
‘content’ => “Original: <span class=\”no_translate\”>$original</span>\nTranslation: <span class=\”no_translate\”>$translation</span>”,
‘primary_link’ => ”,
‘component’ => $bp->blogs->id,
‘type’ => ‘new_translation’,
‘item_id’ => false,
‘secondary_item_id’ => false,
‘recorded_time’ => gmdate(“Y-m-d H:i:s”),
‘hide_sitewide’ => false
);return bp_activity_add($values);
}/**
* This function integrates with google sitemap generator, and adds for each viewable language, the rest of the languages url
* Also – priority is reduced by 0.2
* And this requires the following line at the sitemap-core.php, add-url function (line 1509 at version 3.2.4)
* do_action(‘sm_addurl’, $page);
* @param GoogleSitemapGeneratorPage $sm_page Object containing the page information
*/
function add_sm_transposh_urls($sm_page) {
tp_logger(“in sitemap add url: ” . $sm_page->GetUrl() . ” ” . $sm_page->GetPriority(), 4);
$sm_page = clone $sm_page;
// we need the generator object (we know it must exist…)
$generatorObject = &GoogleSitemapGenerator::GetInstance();
// we reduce the priorty by 0.2, but not below zero
$sm_page->SetProprity(max($sm_page->GetPriority() – 0.2, 0));/* <xhtml:link
rel=”alternate”
hreflang=”de”
href=”https://www.example.com/de” /> */$viewable_langs = explode(‘,’, $this->transposh->options->viewable_languages);
$orig_url = $sm_page->GetUrl();
foreach ($viewable_langs as $lang) {
if (!$this->transposh->options->is_default_language($lang)) {
$newloc = $orig_url;
if ($this->transposh->options->enable_url_translate) {
$newloc = transposh_utils::translate_url($newloc, $this->transposh->home_url, $lang, array(&$this->transposh->database, ‘fetch_translation’));
}
$newloc = transposh_utils::rewrite_url_lang_param($newloc, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, false);
$sm_page->SetUrl($newloc);
$generatorObject->AddElement($sm_page);
}
}
}/**
* This function integrates with yoast sitemap generator, and adds for each viewable language, the rest of the languages url
* Also – priority is reduced by 0.2
* And this requires the following patch in class-sitemaps.php
* For future yoast versions, and reference, look for this function:
if ( ! in_array( $url[‘loc’], $stackedurls ) ) {
// Use this filter to adjust the entry before it gets added to the sitemap
$url = apply_filters( ‘wpseo_sitemap_entry’, $url, ‘post’, $p );
if ( is_array( $url ) && $url !== array() ) {
$output .= $this->sitemap_url( $url );
$stackedurls[] = $url[‘loc’];
}
}And change to:
————————————————————————if ( ! in_array( $url[‘loc’], $stackedurls ) ) {
// Use this filter to adjust the entry before it gets added to the sitemap
$url = apply_filters( ‘wpseo_sitemap_entry’, $url, ‘post’, $p );
if ( is_array( $url ) && $url !== array() ) {
$output .= $this->sitemap_url( $url );
$stackedurls[] = $url[‘loc’];
}
$langurls = apply_filters( ‘wpseo_sitemap_language’,$url);
if ( is_array( $langurls )) {
foreach ($langurls as $langurl) {
$output .= $this->sitemap_url( $langurl );
}
}
}
————————————————————————-
* @param yoast_url array $yoast_url Object containing the page information
*/
function add_yoast_transposh_urls($yoast_url) {
tp_logger(“in sitemap add url: ” . $yoast_url[‘loc’] . ” ” . $yoast_url[‘pri’], 2);
$urls = array();$yoast_url[‘pri’] = max($yoast_url[‘pri’] – 0.2, 0);
$viewable_langs = explode(‘,’, $this->transposh->options->viewable_languages);
$orig_url = $yoast_url[‘loc’];
foreach ($viewable_langs as $lang) {
if (!$this->transposh->options->is_default_language($lang)) {
$newloc = $orig_url;
if ($this->transposh->options->enable_url_translate) {
$newloc = transposh_utils::translate_url($newloc, $this->transposh->home_url, $lang, array(&$this->transposh->database, ‘fetch_translation’));
}
$newloc = transposh_utils::rewrite_url_lang_param($newloc, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, false);
$yoast_url[‘loc’] = $newloc;
$urls[] = $yoast_url;
}
}
return $urls;
}function woo_uri_filter($url) {
$lang = transposh_utils::get_language_from_url($_SERVER[‘HTTP_REFERER’], $this->transposh->home_url);
tp_logger(‘altering woo url to:’ . transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, $this->transposh->edit_mode));
return transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->enable_permalinks_rewrite, $lang, $this->transposh->edit_mode);
}/*
* For the business directory plugin, hidden fields needs to be added to enable search:
* every time after the do-srch param
1. in search.tpl.php added this:
<input type=”hidden” name=”lang” value=”<?php echo transposh_get_current_language(); ?>” />
2. in widget-search.php
printf(‘<input type=”hidden” name=”lang” value=”%s” />’, transposh_get_current_language());
3. templates-ui.php
$html .= sprintf(‘<input type=”hidden” name=”lang” value=”%s” />’, transposh_get_current_language());
*/function fix_wpbdp_cat_links($url) {
tp_logger($url, 1);
return $url;
$url = preg_replace(‘#/.lang=[a-z]*/#’, ‘/’, $url);
if ($this->transposh->options->is_default_language($this->transposh->target_language)) {
return $url;
}
tp_logger($url, 1);
return transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->options->enable_permalinks, $this->transposh->target_language, $this->transposh->edit_mode);
}function fix_wpbdp_links($url) {
tp_logger($url, 1);
$url = preg_replace(‘#/.lang=[a-z]*/#’, ‘/’, $url);
if ($this->transposh->options->is_default_language($this->transposh->target_language)) {
return $url;
}
tp_logger($url, 1);
return transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->options->enable_permalinks, $this->transposh->target_language, $this->transposh->edit_mode);
}function fix_wpbdp_links_base($url) {
if ($this->transposh->options->is_default_language($this->transposh->target_language)) {
return $url;
}
tp_logger($url, 1);
return transposh_utils::rewrite_url_lang_param($url, $this->transposh->home_url, $this->transposh->options->enable_permalinks, $this->transposh->target_language, $this->transposh->edit_mode);
}}
———————————————————–
woocommerce_limit_cart.php<?php
/*
* Plugin Name: Woocommerce Cart Limit
* Plugin URI: https://webmantechnologies.com
* Description: Toolkit for Limit the Cart Quantity, Value and Total.
* Author: Webman Technologies
* Text Domain: wmamc-cart-limit
* Version: 1.2
* Requires at least: 4.4
* Tested up to: 5.2.2
*/
defined( ‘ABSPATH’ ) or exit;
//WC check
$active_plugins = get_option( ‘active_plugins’, array() );
if( !in_array( ‘woocommerce/woocommerce.php’,$active_plugins ) ){
require_once( ABSPATH . ‘wp-admin/includes/plugin.php’ );
deactivate_plugins( plugin_basename( __FILE__ ) );
if( isset( $_GET[‘activate’] ))
unset( $_GET[‘activate’] );
}
class WMAMC_wc_cartLimit {
protected static $instance;
protected $adminpage;
protected $template;
public static $options_set = array(
‘wmamc_enable_cartlimit’,
‘wmamc_cart_max_quanity’,
‘wmamc_cart_min_quanity’,
‘wmamc_cart_max_total’,
‘wmamc_cart_min_total’,
‘wmamc_cat_max_quantity’,
‘wmamc_cart_min_diff_item’,
);
public function __construct() {
//session start
add_action(‘init’, array($this,’WMAMC_register_session’) );
if(‘true’ == $this->WMAMC_get_cart_limit_options(‘wmamc_enable_cartlimit’)){
add_action(‘init’, array($this,’WMAMC_initialize_limits’) );
}
//version check
add_action( ‘admin_init’, array( $this, ‘WMAMC_woo_version_check’ ) );
//add admin page
add_action(‘admin_menu’, array($this, ‘WMAMC_add_menulink’));
//add script and style
add_action( ‘admin_enqueue_scripts’, array( $this, ‘WMAMC_wc_export_review_enqueue’ ) );
//add and update cart limit options
add_action( ‘admin_post_wmamc_cart_limitf’,array( $this,’WMAMC_cart_list_formsave’ ) );
//admin settings
add_action( ‘woocommerce_product_options_advanced’, array($this,’WMAMC_woocommerce_product_options_advanced’), 10, 0 );
add_action( ‘woocommerce_process_product_meta’, array($this,’WMAMC_max_qty_save_product_field’) );
}
public function WMAMC_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
public function WMAMC_initialize_limits(){
$cart_max_quanity = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_max_quanity’);
$cart_min_quanity = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_min_quanity’);
$cart_max_total = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_max_total’);
$cart_min_total = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_min_total’);
$cart_min_diff_item = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_min_diff_item’);
if(‘true’ == $this->WMAMC_get_cart_limit_options(‘wmamc_cat_max_quantity’)){
//add category product max limit
add_action( ‘product_cat_edit_form_fields’, array($this,’wmamc_product_cat_edit_meta_field’), 10, 1 );
add_action( ‘edited_product_cat’, array($this,’wmamc_save_taxonomy_custom_meta’), 10, 2 );
add_action( ‘create_product_cat’, array($this,’wmamc_save_taxonomy_custom_meta’), 10, 2 );
//validate category product limit
add_action( ‘woocommerce_add_to_cart’, array($this,’WMAMC_validate_cat_max_quantity’),15,6 );
add_action( ‘woocommerce_check_cart_items’, array($this,’WMAMC_validate1_cat_max_quantity’),15,0 );
}
//validate single product limit
add_action( ‘woocommerce_add_to_cart’, array($this,’WMAMC_validate_product_max_quantity’),11,6 );
add_action( ‘woocommerce_check_cart_items’, array($this,’WMAMC_validate1_product_max_quantity’),11,0 );
//check max quantity in cart
if($cart_max_quanity != ” && $cart_max_quanity > 0) {
add_action( ‘woocommerce_add_to_cart’, array($this,’WMAMC_validate_cart_max_quantity’),10,6 );
add_action( ‘woocommerce_check_cart_items’, array($this,’WMAMC_validate1_cart_max_quantity’),10,0 );
}
//check min quantity in cart
if($cart_min_quanity != ” && $cart_min_quanity > 0) {
add_action( ‘woocommerce_check_cart_items’, array($this,’WMAMC_validate_cart_min_items’),10,0 );
}
//check max value in cart
if($cart_max_total != ” && $cart_max_total > 0) {
add_action( ‘woocommerce_check_cart_items’, array($this,’WMAMC_validate_cart_max_total’),10,0 );
}
//check min value in cart
if($cart_min_total != ” && $cart_min_total > 0) {
add_action( ‘woocommerce_check_cart_items’, array($this,’WMAMC_validate_cart_min_total’),10,0 );
}
//check min value in cart
if($cart_min_diff_item != ” && $cart_min_diff_item > 0) {
add_action( ‘woocommerce_check_cart_items’, array($this,’WMAMC_validate_cart_min_diff_item’),10,0 );
}
}
public function WMAMC_getWcVersion() {
global $woocommerce;
return $woocommerce->version;
}
public function WMAMC_woo_version_check() {
global $woocommerce;
if ( version_compare( $woocommerce->version, ‘2.4.9’, ‘<=’ ) ) {
add_action( ‘admin_notices’, array($this,’WMAMC_admin_notice_msg’) );
require_once( ABSPATH . ‘wp-admin/includes/plugin.php’ );
deactivate_plugins( plugin_basename( __FILE__ ) );
return false;
}
}
public function WMAMC_register_session(){
//session_start();
}
public function WMAMC_add_menulink() {
$this->adminpage = add_submenu_page(
‘woocommerce’,
__(‘Add Cart Limit’,’wmamc-cart-limit’),
__(‘Add Cart Limit’,’wmamc-cart-limit’),
‘manage_woocommerce’,
‘wmamc_cart_limit’,
array($this, ‘WMAMC_render_submenu_pages’ ),
‘dashicons-format-video’
);
}
public function WMAMC_render_submenu_pages() {
$this->template = $this->WMAMC_get_template(‘cart_limit’);
}
public function WMAMC_wc_export_review_enqueue($hook) {
//add bootstrap to plugin page
if($hook == “woocommerce_page_wmamc_cart_limit”) {
wp_enqueue_style( ‘bootstrap_wp_admin_css’, plugins_url(‘/assets/css/bootstrap_custom.css’, __FILE__),array(),’1′ );
wp_enqueue_script(‘bootstrap_wp_admin_js-script’, plugins_url(‘/assets/js/bootstrap_custom_js.js’, __FILE__ ) , array(‘jquery’), ‘1’, true);
}
wp_enqueue_style(‘woo_cartlimit_s-style’, plugins_url(‘/assets/css/woo_cartlimit.css’, __FILE__ ) );
wp_enqueue_script(‘woo_cartlimit-script’, plugins_url(‘/assets/js/woo_cartlimit.js’, __FILE__ ) , array(‘jquery’), ”, true);
wp_localize_script( ‘woo_cartlimit-script’, ‘plajax’, array(
‘ajax_url’ => admin_url( ‘admin-ajax.php’ )
));
}
public function WMAMC_get_plugin_dir(){
return dirname( __FILE__ );
}
public function WMAMC_get_template($template){
$template_name = ‘template_’.$template.’.php’;
include $this->WMAMC_get_plugin_dir().’/template/’.$template_name;
}
public function WMAMC_get_loader() {
$img = plugin_dir_url( __FILE__ ) .’assets/img/loader.gif’;
$html = “<div class=’WMAMC_loader’ style=’display:none;’ ><center><label>Refreshing …</label></center></div>”;
return $html;
}
public function WMAMC_get_msgbox() {
$html = “<div class=’msg_box’></div>”;
return $html;
}
public function WMAMC_recursive_sanitize_text_field($array) {
foreach ( $array as $key => &$value ) {
if ( is_array( $value ) ) {
$value = WMAMC_recursive_sanitize_text_field($value);
}
else {
$value = sanitize_text_field( $value );
}
}
return $array;
}
public function WMAMC_admin_notice_msg() {
global $woocommerce;
?>
<div class=”notice notice-error is-dismissible”>
<p><?php _e(“<b>Woocommerce Cart Limit is inactive</b>. Woocommerce Cart Limit requires a minimum of WooCommerce v2.5.0″,”wmamc-cart-limit”); ?></p>
</div>
<?php
}
public function WMAMC_cart_list_formsave(){
if ( !current_user_can( ‘manage_options’ ) )
{
wp_die( ‘You are not allowed to be on this page.’ );
}
//Check nonce field
$nonce = sanitize_text_field($_POST[‘wmamc_cart_limit_nonce’] );
if( wp_verify_nonce($nonce,’wmamc_cart_limit_nonce’) ){
if(isset($_POST) && ‘wmamc_cart_limitf’ == sanitize_text_field($_POST[‘action’]) ){
$enable_cl = sanitize_text_field($_POST[‘enable_cart_limit’][0]);
(sanitize_text_field($_POST[‘wmamc_cart_max_quanity’]) !=”) ? $wmamc_cart_max_quanity = (int) sanitize_text_field($_POST[‘wmamc_cart_max_quanity’]) : ”;
(sanitize_text_field($_POST[‘wmamc_cart_min_quanity’]) !=”) ? $wmamc_cart_min_quanity = (int) sanitize_text_field($_POST[‘wmamc_cart_min_quanity’]) : ”;
(sanitize_text_field($_POST[‘wmamc_cart_max_total’]) !=”) ? $wmamc_cart_max_total = (int) sanitize_text_field($_POST[‘wmamc_cart_max_total’]) : ”;
(sanitize_text_field($_POST[‘wmamc_cart_min_total’]) !=”) ? $wmamc_cart_min_total = (int) sanitize_text_field($_POST[‘wmamc_cart_min_total’]) : ”;
(sanitize_text_field($_POST[‘wmamc_cat_max_quantity’]) !=”) ? $wmamc_cat_max_quantity = sanitize_text_field($_POST[‘wmamc_cat_max_quantity’]) : ”;
(sanitize_text_field($_POST[‘wmamc_cart_min_diff_item’]) !=”) ? $wmamc_cart_min_diff_item = sanitize_text_field($_POST[‘wmamc_cart_min_diff_item’]) : ”;
if($enable_cl == ‘true’){
update_option(‘wmamc_enable_cartlimit’,’true’);
}else{
update_option(‘wmamc_enable_cartlimit’,’false’);
}
if($wmamc_cat_max_quantity == ‘true’){
update_option(‘wmamc_cat_max_quantity’,’true’);
}else{
update_option(‘wmamc_cat_max_quantity’,’false’);
}
update_option(‘wmamc_cart_max_quanity’,$wmamc_cart_max_quanity);
update_option(‘wmamc_cart_min_quanity’,$wmamc_cart_min_quanity);
update_option(‘wmamc_cart_max_total’ ,$wmamc_cart_max_total);
update_option(‘wmamc_cart_min_total’ ,$wmamc_cart_min_total);
update_option(‘wmamc_cart_min_diff_item’ ,$wmamc_cart_min_diff_item);
}
}
wp_redirect(admin_url().’/admin.php?page=wmamc_cart_limit’);
//exit;
}
public function WMAMC_get_cart_limit_options($option_key){
return get_option($option_key);
}
public function WMAMC_validate_cart_max_quantity( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
global $woocommerce;
$cart_max_quanity = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_max_quanity’);
$cartQty = $woocommerce->cart->get_cart_item_quantities();
$cart_quantity = 0;
foreach ( $cartQty as $key => $value ) {
$cart_quantity += $value;
}
//
if($cart_max_quanity < $cart_quantity ){
if(array_key_exists($product_id,$cartQty)){
$item = WC()->cart->get_cart_item($cart_item_key);
$item_q = $item[‘quantity’];
$final_q = $item_q – $quantity;
WC()->cart->set_quantity($cart_item_key,$final_q);
}else{
WC()->cart->remove_cart_item($cart_item_key);
}
add_filter( ‘wc_add_to_cart_message’, array($this,’WMAMC_cart_message’ ));
wc_add_notice( sprintf( __( “You can’t have more than $cart_max_quanity items in cart. View Cart“), wc_get_cart_url() ), “error” );
}
}
public function WMAMC_validate_product_max_quantity( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
global $woocommerce;
$product_max_quanity = $this->WMAMC_get_product_max_limit($product_id);
$cartQty = $woocommerce->cart->get_cart_item_quantities();
//
if($product_max_quanity !== false && $product_max_quanity > 0 && $product_max_quanity < $cartQty[$product_id] ){
if(array_key_exists($product_id,$cartQty)){
$item = WC()->cart->get_cart_item($cart_item_key);
$item_q = $item[‘quantity’];
$final_q = $item_q – $quantity;
WC()->cart->set_quantity($cart_item_key,$final_q);
}else{
WC()->cart->remove_cart_item($cart_item_key);
}
$product_title = get_the_title($product_id);
add_filter( ‘wc_add_to_cart_message’, array($this,’WMAMC_cart_message’ ));
wc_add_notice( sprintf(__( “You can’t have more than $product_max_quanity items of $product_title View Cart“), wc_get_cart_url() ), “error” );
}
}
public function WMAMC_validate_cat_max_quantity( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
global $woocommerce;
$product_cat_id = array();
$product_cat_name = array();
//get cart items and filter by category
$cartQty = $woocommerce->cart->get_cart_item_quantities();
foreach ( $cartQty as $key => $value ) {
$terms = get_the_terms( $key, ‘product_cat’ );
foreach ($terms as $term) {
$product_cat_id[$term->term_id][]=$value;
$product_cat_name[$term->term_id]=$term->name;
}
}
//check and add error
foreach($product_cat_id as $cat_id=>$product_cat){
$term_meta = get_option( “taxonomy_$cat_id” );
$cat_limit = $term_meta[‘max_pcat_qty_cart’];
if($cat_limit < array_sum($product_cat) && $cat_limit != ” && $cat_limit > 0 ){
if(array_key_exists($product_id,$cartQty)){
$item = WC()->cart->get_cart_item($cart_item_key);
$item_q = $item[‘quantity’];
$final_q = $item_q – $quantity;
WC()->cart->set_quantity($cart_item_key,$final_q);
}else{
WC()->cart->remove_cart_item($cart_item_key);
}
add_filter( ‘wc_add_to_cart_message’, array($this,’WMAMC_cart_message’ ));
wc_add_notice( sprintf( __(“You can’t have more than %s items of ‘%s’ category. View Cart“, ‘woocommerce’), $cat_limit, $product_cat_name[$cat_id] ,wc_get_cart_url()), ‘error’ );
}
}
}
public function WMAMC_validate1_cart_max_quantity( ) {
global $woocommerce;
$cart_max_quanity = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_max_quanity’);
$cartQty = $woocommerce->cart->get_cart_item_quantities();
$cart_quantity = 0;
foreach ( $cartQty as $key => $value ) {
$cart_quantity += $value;
}
if($cart_max_quanity < $cart_quantity){
wc_add_notice( sprintf( __(‘You can’t have more than %s items in cart’, ‘woocommerce’), $cart_max_quanity ), ‘error’ );
}
}
public function WMAMC_validate1_product_max_quantity( ) {
global $woocommerce;
$cartQty = $woocommerce->cart->get_cart_item_quantities();
$cart_quantity = 0;
foreach ( $cartQty as $key => $value ) {
$product_max_quanity = $this->WMAMC_get_product_max_limit($key);
if($product_max_quanity!== false && $product_max_quanity > 0 && $product_max_quanity < $value){
wc_add_notice( sprintf( __(‘You can’t have more than %s items of %s’, ‘woocommerce’), $product_max_quanity, get_the_title($key) ), ‘error’ );
}
}
}
public function WMAMC_validate1_cat_max_quantity( ) {
global $woocommerce;
$product_cat_id = array();
$product_cat_name = array();
$cartQty = $woocommerce->cart->get_cart_item_quantities();
foreach ( $cartQty as $key => $value ) {
$terms = get_the_terms( $key, ‘product_cat’ );
foreach ($terms as $term) {
$product_cat_id[$term->term_id][]=$value;
$product_cat_name[$term->term_id]=$term->name;
}
}
//check category limit and add error
foreach($product_cat_id as $cat_id=>$product_cat){
$term_meta = get_option( “taxonomy_$cat_id” );
$cat_limit = $term_meta[‘max_pcat_qty_cart’];
if($cat_limit < array_sum($product_cat) && $cat_limit != ” && $cat_limit > 0 ){
wc_add_notice( sprintf( __(“You can’t have more than %s items of ‘%s’ category. “, ‘woocommerce’), $cat_limit, $product_cat_name[$cat_id] ), ‘error’ );
}
}
}
public function WMAMC_validate_cart_min_items( ) {
global $woocommerce;
$cart_min_quanity = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_min_quanity’);
$cartQty = $woocommerce->cart->get_cart_item_quantities();
$cart_quantity = 0;
foreach ( $cartQty as $key => $value ) {
$cart_quantity += $value;
}
if($cart_min_quanity > $cart_quantity){
wc_add_notice( sprintf( __(‘You need to buy minimum %s products’, ‘woocommerce’), $cart_min_quanity ), ‘error’ );
}
}
public function WMAMC_validate_cart_max_total( ) {
global $woocommerce;
$cart_max_total = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_max_total’);
$cartQty = $woocommerce->cart->get_cart_item_quantities();
$cart_subtotal = 0;
foreach ( WC()->cart->get_cart() as $key => $value ) {
$cart_subtotal += $value[‘line_subtotal’];
}
if($cart_max_total < $cart_subtotal){
$currency = get_option(‘woocommerce_currency’);
$currency_symbol = get_woocommerce_currency_symbol($currency);
wc_add_notice( sprintf( __(‘You need to buy maximum of %s value products’, ‘woocommerce’), $currency_symbol.$cart_max_total ), ‘error’ );
}
}
public function WMAMC_validate_cart_min_total( ) {
global $woocommerce;
$cart_max_total = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_min_total’);
$cartQty = $woocommerce->cart->get_cart_item_quantities();
$cart_subtotal = 0;
foreach ( WC()->cart->get_cart() as $key => $value ) {
$cart_subtotal += $value[‘line_subtotal’];
}
if($cart_max_total > $cart_subtotal){
$currency = get_option(‘woocommerce_currency’);
$currency_symbol = get_woocommerce_currency_symbol($currency);
wc_add_notice( sprintf( __(‘You need to buy minimum of %s value products’, ‘woocommerce’), $currency_symbol.$cart_max_total ), ‘error’ );
}
}
public function WMAMC_validate_cart_min_diff_item( ) {
global $woocommerce;
$cart_min_quanity = $this->WMAMC_get_cart_limit_options(‘wmamc_cart_min_diff_item’);;
$cartQty = $woocommerce->cart->get_cart();$cart_quantity = 0;
foreach ( $cartQty as $key => $value ) {$cart_quantity++;
}
if($cart_min_quanity > $cart_quantity){
wc_add_notice( sprintf( __(‘You need to buy minimum %s different products’, ‘woocommerce’), $cart_min_quanity ), ‘error’ );
}}
public function WMAMC_woocommerce_product_options_advanced( ) {
echo ‘<div class=”options_group”>’;
woocommerce_wp_text_input(
array(
‘id’ => ‘_wmamc_max_qty_product_max’,
‘label’ => __( ‘Max Quantity Per Order’, ‘wmamc-cart-limit’ ),
‘placeholder’ => ”,
‘desc_tip’ => ‘true’,
‘description’ => __( ‘Optional. Set a maximum quantity limit allowed per order. Enter a number, 1 or greater.’, ‘wmamc-cart-limit’ )
)
);
echo ‘</div>’;
}
public function WMAMC_max_qty_save_product_field( $post_id ) {
$val = trim( get_post_meta( $post_id, ‘_wmamc_max_qty_product_max’, true ) );
$new = (int)sanitize_text_field( $_POST[‘_wmamc_max_qty_product_max’] );
if ( $val != $new ) {
update_post_meta( $post_id, ‘_wmamc_max_qty_product_max’, $new );
}
}
public function WMAMC_get_product_max_limit( $product_id ) {
$qty = get_post_meta( $product_id, ‘_wmamc_max_qty_product_max’, true );
if ( empty( $qty ) ) {
// honor the Sold individually setting
$product = wc_get_product( $product_id );
$limit = $product->is_sold_individually() ? 1 : false;
} else {
$limit = (int) $qty;
}
return $limit;
}
public function wmamc_product_cat_edit_meta_field($term){
$t_id = $term->term_id;
$term_meta = get_option( “taxonomy_$t_id” ); ?>
<tr class=”form-field”>
<th scope=”row” valign=”top”><label for=”term_meta[max_pcat_qty_cart]”><?php _e( ‘Max Product Quantity ‘, ‘wmamc-cart-limit’ ); ?></label></th>
<td>
<input type=”number” min=”0″ name=”term_meta[max_pcat_qty_cart]” id=”term_meta[max_pcat_qty_cart]” value=”<?php echo esc_attr( $term_meta[‘max_pcat_qty_cart’] ) ? esc_attr( $term_meta[‘max_pcat_qty_cart’] ) : ”; ?>”>
<p class=”description”><?php _e( ‘Enter a value for maximum product allowed in cart for this catgory.’,’wmamc-cart-limit’ ); ?></p>
</td>
</tr>
<?php
}
public function wmamc_save_taxonomy_custom_meta( $term_id ) {
if ( isset( $_POST[‘term_meta’] ) ) {
$t_id = $term_id;
$term_meta = get_option( “taxonomy_$t_id” );
$cat_keys = array_keys( $_POST[‘term_meta’] );
foreach ( $cat_keys as $key ) {
$term_meta_val = sanitize_text_field($_POST[‘term_meta’][$key]);
if ( isset ( $_POST[‘term_meta’][$key] ) ) {
$term_meta[$key] = $term_meta_val;
}
}
// Save the option array.
update_option( “taxonomy_$t_id”, $term_meta );
}
}
public function WMAMC_cart_message() {
return ”;
}
}
function WMAMC_wc_cartLimit() {
return WMAMC_wc_cartLimit::WMAMC_instance();
}
WMAMC_wc_cartLimit();
?>
-end-
It is hard to repair some issues with plugins installed in my site and server error and I decided to use previous translation plugin for the time being.
Thanks a lot so far!JiYeon
- The topic ‘Can’t save translation’ is closed to new replies.