Redirect WooComerce to a custom URL after login

If you are sending a URL like: http://site.com/my-account?redirect_to=product-xpto

Open woocommerce/myaccount/form-login.php and add:

<input type=”hidden” name=”redirect” value=”<?= $_GET[‘redirect_to’]; ?>”>

WooComerce: Restrict payment method by product category

This is a custom filter to restrict certain payment methods on the WooCommerce, considering the product categories.

add_filter('woocommerce_available_payment_gateways','restrict_gateways');

function restrict_gateways($gateways){

    $payment_name = 'your_payment_id';
    $product_category = 'your_category_name';

    global $woocommerce;

    foreach ($woocommerce->cart->cart_contents as $key => $values ) {
        
        $terms = get_the_terms( $values['product_id'], 'product_cat' );
        
        if (! $terms) {
            unset($gateways[$payment_name]);
            break;
        }
        
        foreach ($terms as $term) {
        
            if ( $term->name != $product_category ) {
                unset($gateways[$payment_name]);
                break;
            }
        
            break;
        }
    }

    
    return $gateways;

}

Add subtitle to WooCommerce product

In this tip, we are using the Kia Subtitle plugin, so please download and install the plugin before next steps.

After install and active, open your functions.php and add the code below:


            

These lines above are self-explained. They allow you to display the subtitle content at the product and shop pages.

How to `git clone` including submodules?

With version 1.7.1 of Git and later, you can use:

git clone --recursive git://github.com/foo/bar.git
cd bar

For already cloned repositories, just use:

cd clonde-repository
git submodule update --init --recursive

How to add a git submodule?

To add another git repository as submodule to your main repository, just use this command:

cd repository
git submodule add git://github.com/foo/bar.git submodules-dir/bar

Disable Automatic Updates in WordPress

As any WordPress Developer, I love the updates from the contributors of the ecosystem. Their updates help me to avoid hacks and other knowing issues about the system.

But, sometimes these updates can break the entire theme. So, to avoid the automatic WordPress updater you can add the property below inside the wp-config.php:


define('AUTOMATIC_UPDATER_DISABLED', true);

Linux useful commands: “ls” command

Hi people, every wednesday I bring here quick tips to make your life easy in managing Linux environments. Today I choosed the the most used command on Linux enviroments, in my opinion.

The command “ls”

We use this command every time when working with command prompt. You can see some useful tips to work better with it:

1) Listing all files (including hidden) with directory, size, modified date and time, file or folder name and owner of file and it’s permission in human readable format.

$ ls -lsahF

2) Reversing the order

$ ls -lsahFr

3) Including sub-directories recursively

$ ls -lsahFR

4) Sorting by File Size

$ ls -lsahFS

References:

http://www.tecmint.com/15-basic-ls-command-examples-in-linux/

WordPress Speed Optmization

Hi people. I am back here bringing a serie of articles with strategies to optimize the performance and speed of a WordPress installation. I will cover these topics every monday:

  • Webserver
  • Caching
  • CDN
  • Backend
  • Database
  • Memory Cache
  • Improvements on static files
  • And much more

To introduce these topics, I would like to talk a little bit about me and my experience. During the last years I have been working with WordPress and how to extract the maximum potential of servers.

This task is not so difficulty, because the WordPress system is not so heavy to load. But the problem is when people use your creativity to create a problematic environments. Lots of plugins, poorly code and million of static files to manage are the perfect combination to make your WordPress weeps.

So, I expect you here next monday to talk more about caching strategies. This journey is just beginning. See you later.

WooCommerce and Webhooks

The webhook system of WooCommerce, which is present since a few versions ago, got a good web interface to manage creation and interaction with hooks. For whom do not know what webhooks mean, we can summarize like:

 

It is a mechanism that you can monitor notification of systems, by using an API, usually allowing to register an URL which runs a program to interpret the received notifications.

 

With this system, it is possible to monitor events ocurred on WooCommerce. For example, we can monitor new orders and send alerts for sales team to get in touch (it was only a simple example, there is many actions available to monitor).

You can check the full documentation here: http://docs.woothemes.com/document/webhooks/.

Enable CORS for Nginx

Whom have worked with cross-origin HTTP requests knows that one of the actions to make this working is enable CORS in API’s webserver .

As I work with Nginx, the code that warns browsers (Firefox e Chrome) and allow pre-flight requests is presented below:

https://gist.github.com/6398833248000894b05b

The flow of this browsers is: making a pre-flight request to test the webserver, before making the real request. The code above allow the cross-origin request flow goes ahead. You will need to implement this code between “location” block.

More informations in Enable CORS and here. Hope this useful.