How to Completely Uninstall/Remove WooCommerce and Data

Posted by on Aug 10, 2017 in WooCommerce | 0 comments

The complete removal of WooCommerce and its data is not (or should not be) a common thing but it might be useful if you need to go back to previous version of WooCommerce or if just want to start from scratch or if you need to delete some test orders. Here's a video how to do it. If you deactivate WooCommerce and uninstall like you do with any other WordPress plugin this won’t delete the orders and customer data which makes sense otherwise lots of people would freak out. The only extra step that needs to be done first before you attempt to uninstall WooCommerce is to edit your wp-config.php file and append one line. You need to add this line right after the starting <?php tag. define( 'WC_REMOVE_ALL_DATA', true); To edit that file you will need to use an ftp client (e.g. FileZilla). Do make sure that the quotes are correctly pasted (e.g. single quotes look like single quotes) because if they aren’t this can/will crash your site. If you get an error you can manually delete the quotes around WC_REMOVE_ALL_DATA and type them again and upload the file. Some may wonder why there isn’t a button that can be checked to confirm data deletion. The problem is people don’t read and especially if they are tired or if they don’t know what they are doing they can click on the wrong checkbox and the order data would be lost. Sometimes the user needs to be protected from themselves.   To recap the complete WooCommerce uninstallation steps Add the line in the wp-config.php to confirm that you really want the data removed Deactivate the WooCommerce plugin Uninstall the WooCommerce plugin Maybe reinstall WooCommerce plugin Remove the line from the wp-config.php in case you uninstall the plugin later.   Related   Do you use test/staging sites? Visit qSandbox for more...

Read More

Decisiveness: Quality 1 of N of Successful Entrepreneurs

Posted by on Aug 9, 2017 in Business, Entrepreneurship | 0 comments

Being decisive is a cool and very important quality. It requires energy and you to face fears of being wrong or even to look stupid. It takes guts to be decisive but there’s no success without decisiveness. It is an important quality not only in business but also in personal life because decisions unstuck you. You decide which road to take and that makes some of the problems irrelevant and other ones more relevant and that is a good thing. It’s better to solve issues that are right in front of your eyes rather than spend time and energy fixing things that might or might not happen in 1 year. In programming terms this is called premature optimization. It’s good to look ahead but not too far ahead and only when it really makes sense. Many books state that we have a limited pool of energy that we can use for decision per day. Every decision takes some of its contents. With the new day that pool gets replenished. Even micro decisions take mental energy e.g. what clothes/socks to wear, what to eat for breakfast, do you want to drink tea or coffee. To simplify this you can have rules to improve the decision making process. For example: you can prepare your clothes for the next day. You can cereal during the week days and on pancakes on the weekend. Deciding between: coffee or tea. Anytime between 5am & 4pm drink coffee otherwise tea. There will be days when you’ve had to exercise your decision power and lot and at the end of the day you feel drained and deciding what to order for dinner can take minutes to make. That’s normal and is ok. What if I make the wrong decision? I was raised that making mistakes is a wrong thing. Thankfully I was able to change my perception by reading lots of startup/business books. Those books repeatedly mentioned that mistakes are just learning lessons. In the context of startups many decisions/experiments have to be made in order to find a working business model i.e. create something that people want and are willing to pay money for it & are actively looking for a solution. Most of the time it’s better to make a decision early on because you’ll be able to course correct if things don’t work out as expected or you get new information that makes you change course. In one of the business books I remember reading that a CEO mentioned that he/she has changed their mind rather than saying he/she was wrong J.   There are small other cases/exceptions that makes sense to delay making a decision they are called creative procrastination. I like...

Read More

How to Make Some Required Fields Optional on WooCommerce Checkout Page

Posted by on Aug 7, 2017 in WooCommerce | 0 comments

WooCommerce allows you to quickly start an e-commerce store. At some point you may need to customize some of the checkout fields to fit your project requirements. WooCommerce like other well written plugins uses hooks extensively. Those are actions and filters which allow you or your developer to customize the WooCommerce functionality without hacking the code. Another benefit of using hooks is that those customizations will survive any WooCommerce updates. Here's a link to the file (next do Save as) : orbisius_quick_fix_wc_ext_opt_co_fields.php <?php /* This code allows you to make some WooCommerce Checkout Fields optional. Blog post Author: Svetoslav Marinov (Slavi) Author URI: */ /* Installation 1. Paste the code below in your functions.php OR create an mu-plugin in wp-content/mu-plugins/orbisius_quick_fix_wc_ext_opt_co_fields.php 2. Define which fields you want optional by putting this in your wp-config.php You can see the fields on the blog post about this fix at define('ORBISIUS_QUICK_FIX_WOO_OPTIONAL_CHECKOUT_FIELDS', 'first_name,last_name' ); 3. If you want a customizaiton ($) contact me. */ add_filter( 'woocommerce_checkout_fields', 'orbisius_quick_fix_wc_ext_opt_co_fields_make_optional_fields', 25); add_filter( 'woocommerce_billing_fields', 'orbisius_quick_fix_wc_ext_opt_co_fields_make_optional_fields', 25); add_filter( 'woocommerce_default_address_fields', 'orbisius_quick_fix_wc_ext_opt_co_fields_make_optional_fields', 25); /** * This function does the heavy lifting to make fields optional. * @param array $fields * @return array * @copyright (c) 2017 Slavi Marinov, */ function orbisius_quick_fix_wc_ext_opt_co_fields_make_optional_fields($fields) { static $optional_fields = null; // Don't know what to process so let's get out of here. if (!defined('ORBISIUS_QUICK_FIX_WOO_OPTIONAL_CHECKOUT_FIELDS')) { return $fields; } if (is_null($optional_fields)) { $optional_fields = preg_split('#\s*[\,\;\|\r\n]+\s*#si', ORBISIUS_QUICK_FIX_WOO_OPTIONAL_CHECKOUT_FIELDS ); $optional_fields = array_unique($optional_fields); $optional_fields = array_filter($optional_fields); } // Nothing to process so let's get out of here. if (empty($optional_fields)) { return $fields; } foreach ($optional_fields as $field_key) { if (isset($fields[$field_key])) { $fields[$field_key]['required'] = false; } if (isset($fields['shipping'][$field_key])) { $fields[$field_key]['shipping']['required'] = false; } if (isset($fields['billing'][$field_key])) { $fields[$field_key]['billing']['required'] = false; } // do we have fields that don't have a prefix? $no_prefix_key = $field_key; $no_prefix_key = preg_replace( '#(billing|shipping)_#si', '', $no_prefix_key); if (isset($fields[$no_prefix_key])) { $fields[$no_prefix_key]['required'] = false; } if (isset($fields['shipping'][$no_prefix_key])) { $fields[$no_prefix_key]['shipping']['required'] = false; } if (isset($fields['billing'][$no_prefix_key])) { $fields[$no_prefix_key]['billing']['required'] = false; } } return $fields; } Here are all of the Shipping & Billing fields from all the filters. array ( 'first_name' => array ( 'label' => 'First name', 'required' => false, 'class' => array ( 0 => 'form-row-first', ), 'autocomplete' => 'given-name', 'autofocus' => true, 'priority' => 10, ), 'last_name' => array ( 'label' => 'Last name', 'required' => false, 'class' => array ( 0 => 'form-row-last', ), 'autocomplete' => 'family-name', 'priority' => 20, ), 'company' => array ( 'label' => 'Company name', 'class' => array ( 0 => 'form-row-wide', ), 'autocomplete' => 'organization', 'priority' => 30, ), 'country' => array ( 'type' => 'country', 'label' => 'Country', 'required' => true, 'class' => array ( 0 => 'form-row-wide', 1 => 'address-field', 2 => 'update_totals_on_change', ), 'autocomplete' =>...

Read More

How to Reset Download Limits of WooCommerce Downloadable Products

Posted by on Aug 2, 2017 in WooCommerce | 0 comments

WooCommerce allows you to sell all kind of products. My favourites are the downloadable or e-products. By e-products I mean products such as ebooks, reports, software. E-products are great because you don’t have to ship anything physical and they allow for instant download / delivery. When you add the product to WooCommerce you can set some limits e.g. how many times a product can be downloaded and when the download will expire. After a user has reached their download limits (or the download has expired) WooCommerce will block the access to that file. This is a good safely measure because that way people won’t be able to share the download link with other people.   What to do when your Virtual/Downloadable products have changed? Let’s say you want to send a mass email to let your customers know that you have a new version of your e-product. This could be because you’ve created a 2nd edition of your ebook, report or fixed some glitches in the software. Whatever the reason you want people to be able to access the files again regardless of how many times they have downloaded the file(s) in the past.   How WooCommerce manages the downloadable products’ limits As with anything in life there are many ways to get the job done. Let’s first cover how WooCommerce manages the download limits for downloadable products.  WooCommerce keeps track of the limits in a custom table called: YOUR_DB_TABLE_PREFIX_woocommerce_downloadable_product_permissions which links the order, product, and user together. After each download WooCommerce will decrease the downloads_remaining field. After it reaches 0, no more downloads will be allowed for that user and that product.   CREATE TABLE IF NOT EXISTS `default_db_wp_woocommerce_downloadable_product_permissions` ( `download_id` varchar(32) NOT NULL, `product_id` bigint(20) unsigned NOT NULL, `order_id` bigint(20) unsigned NOT NULL DEFAULT '0', `order_key` varchar(200) NOT NULL, `user_email` varchar(200) NOT NULL, `user_id` bigint(20) unsigned DEFAULT NULL, `downloads_remaining` varchar(9) DEFAULT NULL, `access_granted` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `access_expires` datetime DEFAULT NULL, `download_count` bigint(20) unsigned NOT NULL DEFAULT '0', `permission_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`permission_id`), KEY `download_order_product` (`download_id`,`order_id`,`product_id`), KEY `download_order_key_product` (`product_id`,`order_id`,`order_key`,`download_id`), KEY `order_id` (`order_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; In order to reset the download limits we need to modify downloads_remaining & access_expires fields.   To reset the download limits for all products and all users you need to execute this SQL command in phpMyAdmin UPDATE `default_db_wp_woocommerce_downloadable_product_permissions` SET downloads_remaining = 5, access_expires = DATE_ADD(NOW(), INTERVAL 7 DAY)   To reset the download limits for a selected product you need to execute this SQL command in phpMyAdmin UPDATE `default_db_wp_woocommerce_downloadable_product_permissions` SET downloads_remaining = 5, access_expires = DATE_ADD(NOW(), INTERVAL 7 DAY) WHERE product_id = 123 To reset the download limits for a selected user ID...

Read More

How to Restrict Access to WordPress Uploads Folder to Logged-in Users only

Posted by on Apr 6, 2017 in WordPress | 0 comments

Edit: I've received some valuable feedback from Reddit users: cabalos & zware. It seems the following approach may be bypassed by an experienced developer. Will come up with an alternative solution and update this post again. !!Edit2:!! For a far more effective protection check the free plugin below. It uses the technique mentioned in this post and also combines it with a system WordPress plugin to do more thorough checks. Below is the 2nd video which demonstrates the more effective approach in protecting WP Media Uploads folder. Orbisius WP Media Protector When you upload files in WordPress by default they go to wp-content/uploads folder. Those files are normally accessible from the browser and it is supposed to be that way because the transfer is faster. Serving files from php, perl etc would take additional resources. What if you have project that requires all files to be accessible to the logged in users only? For example this could be an internal site that allows employees, vendors can upload documents. The admin creates the accounts on demand and it’s tightly controlled who gets access to the site. Here is a video demo how to do it.   Here some snippets for Apache web server that need to be added to the .htaccess file which resides in the folder where WordPress is installed. Option 1: Full Restriction: How to restrict access to all files from residing in the WordPress uploads folder. # Protect all files within the uploads folder <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_COOKIE} !.*wordpress_logged_in.*$ [NC] RewriteCond %{REQUEST_URI} ^(.*?/?)wp-content/uploads/.* [NC] RewriteRule . http://%{HTTP_HOST}%1/wp-login.php?redirect_to=%{REQUEST_URI} [L,QSA] </IfModule> Option 2: Partial Restriction: How to restrict access to only to some files (based on their extension) in the uploads folder. # Protect only some files within the uploads folder <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_COOKIE} !.*wordpress_logged_in.*$ [NC] RewriteCond %{REQUEST_URI} ^(.*?/?)wp-content/uploads/.*\.(?:gif|png|jpe?g|pdf|txt|rtf|html|htm|xlsx?|docx?|mp3|mp4|mov)$ [NC] RewriteRule . http://%{HTTP_HOST}%1/wp-login.php?redirect_to=%{REQUEST_URI} [L,QSA] </IfModule>   Note: This works for Apache web server and can be tweaked to work with nginx as well.   How it works? Apache mod_rewrite module checks to see if there’s a cookie whose name contains  “wordpress_logged_in”. If it doesn’t exist that means that the user is not logged in. Next rule checks if the user is trying to access a file in the uploads folder. Based on the which option you’ve picked the rules check if it’s any file is accessed from within uploads OR a file with a known extension. The last line redirects the user to the login page and if they successfully login then they’ll be redirected to the file they have tried to access. Other solutions just redirect to random locations or output an access denied error message. Note: WordPress’ uses a php constant called...

Read More
We're working on a free WordPress migration service called Check the site to learn more ;)