How to Programmatically Create/Update a Shipping Zone in WooCommerce

Posted by on Jul 7, 2016 in WooCommerce | 0 comments

With WooCommerce 2.6 you can have different shipping zones, File that is responsible for zone creation: /woocommerce/includes/class-wc-shipping-zone.php Here's how to create a shipping zone with php. Make sure the code is executed on or after init action to be sure that all the plugins are fully loaded. $zone_data = new stdClass(); $zone_data->zone_name = 'New Zone Name'; //$zone_data->zone_id = 12; // uncomment for update $zone_obj = new WC_Shipping_Zone( $zone_data ); $zone_obj->save(); $zone_id =...

Read More

How to Convert a Date into User's Timezone Using PHP & JavaScript

Posted by on Jul 7, 2016 in Web Development | 0 comments

How to Convert a Date into User's Timezone Using PHP & JavaScript I needed to convert a date that is in PST (GMT-8) to date based on user's timezone. I had to find a way to get user's timezone and pass it to php so it can do the conversion. Here's the approach: Guess the timezone using momentjs and pass it to php and let it do the conversion. Steps 1. Download the minified versions of momentjs & momentjs-timezone http://momentjs.com/timezone/ 2. Include the files in your page <script src="share/momentjs/moment.min.js"></script> <script src="share/momentjs/moment-timezone-with-data-2010-2020.min.js"></script> 3. Guess the timezone with JavaScript var tz = ''; try { // moment js + moment timezone tz = moment.tz.guess(); } catch (e) {} // use tz and pass it to php via ajax or in a hidden field // index.php?tz=America/Toronto 4. Use it in php <?php $tz = empty( $_REQUEST['tz'] ) ? '' : $_REQUEST['tz']; $date = date( 'Y-m-d H:i:s' ); echo "The date is: " . orbisius_date_util::correct_date( $date, $tz ); class orbisius_date_util {     /**      * Recalculates the dates from one (base) timezone to another.      * We're using momentjs to detect user's timezone which is passed with the search filters.      * orbisius_date_util::correct_date();      *      * @param str $starting_date - July 6, 2016 14:00:00, 2016-11-26 6pm, 2016-11-26 22:00:00      * @param str $user_tz      * @return str      */     public static function correct_date( $starting_date, $user_tz = 'America/Toronto', $fmt = 'Y-m-d H:i:s' ) {         try {             // if the user timezone is invalid we won't modify the date.             $date = $starting_date;                          // http://php.net/manual/en/datetime.settimezone.php             $base_tz = new DateTimeZone( 'America/Vancouver' );             $date_obj = new DateTime( $starting_date, $base_tz );             $date_obj->setTimezone( new DateTimeZone( $user_tz ) );             $date = $date_obj->format( $fmt );         } catch ( Exception $e ) {             // Probably wrong date timezone.         }         return $date;     } } Related http://momentjs.com/timezone/ http://stackoverflow.com/questions/11883757/convert-utc-datetime-to-another-timezone-php...

Read More

How to Globally Block IP addresses in Apache

Posted by on Jun 13, 2016 in Servers | 0 comments

Spammers are everywhere. Even though it's a cat and mouse game it feels so good when we can block them :) This tutorial assumes that you have root access to the server. This example is tested on Ubuntu but should work for any apache installation. Steps Create a file called /etc/apache2/conf-available/00_block_ips.conf with the following contents. ErrorDocument 403 "The content is not available. If you think this is an error contact us via domain.com" # Global ip blocklist <Directory "/var/www/"> deny from 1.2.3.4 # some explanation </Directory> Enable the cofig file. a2enconf 00_block_ips We file starts with 00 so it's one of the first conf files to be loaded. You should see something like this. Enabling conf 00_block_ips. To activate the new configuration, you need to run: service apache2 reload Reload apache conf service apache2 reload Feel free to customize the text in the quotes after ErrorDocument 403 so people who were accidentally blocked can do something about it. If you want to temporarily disable the ip block do this a2disconf 00_block_ips service apache2...

Read More

How to Translate WooCommerce into Your Language

Posted by on May 25, 2016 in WooCommerce | 0 comments

There's tons of articles explaining what WooCommerce is and how much its market share is so I am going straight to get to the point. It seems after a certain version WooCommerce team has decided not to ship language packs with the plugin. You have been probably wondering why your site is in different language and WooCommerce keeps showing its screens in English i.e. ignoring the WPLANG (constant or settings option). The benefit of shipping the language packs separately is that WooCommerce will take less space and will be quicker to install and update. The language packs can be downloaded from the link below. https://github.com/woothemes/woocommerce-language-packs/tree/master/packages After you download the selected language pack you need to unzip it into the following directory. Do make sure that the unzipped files are in that folder and not in a subfolder. YOUR_WP_DIR/wp-content/languages/plugins/ For example if you want to switch to the Bulgarian language here is how the files in the folder should look like i.e. not in a subfolder. YOUR_WP_DIR/wp-content/languages/plugins/woocommerce-admin-bg_BG.mo YOUR_WP_DIR/wp-content/languages/plugins/woocommerce-admin-bg_BG.po YOUR_WP_DIR/wp-content/languages/plugins/woocommerce-bg_BG.po YOUR_WP_DIR/wp-content/languages/plugins/woocommerce-bg_BG.mo   If you haven't changed the default WordPress language you can do so by going to: WP Admin > Settings > General > Site Language and pick the language from the dropdown menu. Here is a video how to do the steps.   Common issues / questions. woocommerce admin is still in English woocommerce fix WPLANG woocommerce ignores WPLANG woocommerce ignores $locale define('WPLANG', 'SOME_LANGUAGE'); - this probably no longer works. Did your WordPress site ever crash because bad plugins or themes? Next time you should use...

Read More

How to Navigate Between WordPress Pages, Posts, WooCommerce Products Like a Pro

Posted by on Apr 15, 2016 in WordPress Tips | 0 comments

Managing content is a must nowadays. It is important to share knowledge and especially if you want to attract the right customers. Even though it takes only a few clicks to get to another page or post these extra steps can break your flow. Studies show that when you get interrupted it can take 15 minutes if not more to get back to where you were. Since you want to be super effective here a free plugin called Orbisius Quick Nav allows you to quickly switch between pages, posts, WooCommerce products, orders and other custom post types with ease. Even if you have many pages or products it has a filter that simplifies the search. Download the plugin from WordPress.org https://wordpress.org/plugins/orbisius-quick-nav/ Setup WordPress site in seconds? No way! Don't believe me? Visit qSandbox for more...

Read More

How to Compile LFTP from Source

Posted by on Feb 14, 2016 in Howto | 0 comments

Download the latest version from http://lftp.yar.ru/ apt-get install -y gcc build-essential automake readline-common libreadline6-dev pkg-config libgnutls-dev ncurses-dev I've run into many errors during the configure process but this GitHub ticket helped me https://github.com/lavv17/lftp/issues/58 Untar/unzip and then ./configure make make check make install make clean make distclean Errors I've run into. DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS" configure: error: in `/.../lftp-4.6.5': configure: error: The pkg-config script could not be found or is too old.  Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config. Alternatively, you may set the environment variables LIBGNUTLS_CFLAGS and LIBGNUTLS_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. configure: error: Package requirements (gnutls >= 1.0.0) were not met: No package 'gnutls' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables LIBGNUTLS_CFLAGS and LIBGNUTLS_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. configure: error: Package requirements (gnutls >= 1.0.0) were not met: No package 'gnutls' found lftp_tinfo.cc: In function âvoid init_terminfo()â: lftp_tinfo.cc:53:33: error: âsetuptermâ was not declared in this scope if(setupterm(NULL, 1, &errret) == ERR) ^ lftp_tinfo.cc:53:38: error: âERRâ was not declared in this scope if(setupterm(NULL, 1, &errret) == ERR) ^ lftp_tinfo.cc: In function âconst char* get_string_term_cap(const char*, const char*)â: lftp_tinfo.cc:71:63: error: âtigetstrâ was not declared in this scope const char *ret = tigetstr(const_cast<char *>(terminfo_cap)); ^ make[1]: *** [lftp_tinfo.lo] Error 1 make[1]: Leaving directory `/var/www/vhosts/qsandbox.com/users/3/2/qsu32/sites/postpartner2016.qsandbox.com/lftp-4.6.5/src' make: *** [all-recursive] Error 1 Setup WordPress site in seconds? No way! Don't believe me? Visit qSandbox for more...

Read More