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 https://docs.woocommerce.com/document/installing-uninstalling-woocommerce/   Can you set up a test/staging WordPress sites in seconds? Yes, with qSandbox you...

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 http://orbisius.com/link/3710 Author: Svetoslav Marinov (Slavi) Author URI: http://orbisius.com */ /* 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 http://orbisius.com/link/3710 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, http://orbisius.com */ 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 Make WooCommerce Refresh its cart-contents Widget

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

I am not going to start with pointless intro about WooCommerce and how many sites WooCommerce powers. If you're reading this post you know for sure what it does so I will just dive in. In a recent update of our WooCommerce plugin which allows bulk product adding we've added Ajax add to cart so the clients can stay on the same page in case they want to add more products a few seconds later. This has to be enabled from the plugin's Settings which can be found in WP Admin > Settings > Orbisius Quick Order for WooCommerce. One of our customers & also great beta tester Annie (Hi Annie) noticed that the WooCommerce cart-contents widget wasn't refreshing i.e. the user adds one or more products to the shopping cart, the page correctly doesn't refresh but the widget that shows the current total didn't change at all. Same thing for mobile view as well. This was happening with the Storefront theme. I started digging into WooCommerce & Storefront theme and found the piece of code that was responsible for triggering and refreshing the so called fragments. WooCommerce makes an Ajax call and receives a JSON back . The JSON nicely includes with different fields that contain HTML code that can be used to replace different sections on the page. A theme or a plugin can/will handle the add to cart and make some (visual) changes. The code that reloads those fragments can be found here: \plugins\woocommerce\assets\js\frontend\cart-fragments.js To refresh WooCommerce widget you have to copy the code below var $fragment_refresh = { url: wc_cart_fragments_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_refreshed_fragments' ), type: 'POST', success: function( data ) { if ( data && data.fragments ) { $.each( data.fragments, function( key, value ) { $( key ).replaceWith( value ); }); if ( $supports_html5_storage ) { sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( data.fragments ) ); set_cart_hash( data.cart_hash ); if ( data.cart_hash ) { set_cart_creation_timestamp(); } } $( document.body ).trigger( 'wc_fragments_refreshed' ); } } }; ... and to trigger the event you do this: $.ajax( $fragment_refresh ); or jQuery.ajax( $fragment_refresh ); Note: if you have this snippet code in php you may have to rename $fragment_refresh to my_plugin_fragment_refresh so the dollar sign $ doesn't get interpreted as php variable. Ideal way It would have been awesome if we can trigger the fragments to reload with a simple custom jQuery event and not to have to copy and paste code above. $( document.body ).trigger( 'wc_reload_fragments' ); or $( document.body ).trigger( 'wc_force_reload_fragments'...

Read More

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 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. Do you use test/staging sites? Visit qSandbox for more...

Read More