pátek 19. února 2016

How to change Woocommerce default ajax loader icon in Cart and Checkout

This little snippet will going to change your loader icon in WooCommerce Cart and Checkout.

In Cart you should see this icon when you update Shipping.
In Checkout you see this when you update Shipping or Sending an Order.

You should first create a new gif icon you want to use.
I'm using this generator: PreLoaders.NET

This is our .gif which size is 128px*128px. WooCommerce default loader is only 16px*16px which is pretty small.

The following code will change the loader in Cart and Checkout. If you need it only on CheckOut, delete the is_cart from if syntax. Add the code to you themes functions.php file.

add_filter('woocommerce_ajax_loader_url', 'woo_custom_cart_loader');
function woo_custom_cart_loader() {
 
 global $woocommerce;
 
 if(is_checkout() || is_cart()){
  return __(get_template_directory_uri().'/images/loader-ajax-new.gif', 'woocommerce');
    }
 else
  return __(get_template_directory_uri().'/images/ajax-loader@2x.gif', 'woocommerce');
}

The second thing you need to do is to increase the size of the loader icon, we told that this icon is only 16px*16px. So after uploading image to the themes /images folder or your custom places head to these files:

To increase the Cart loader icon: /wp-content/plugins/woocommerce/assets/js/frontend/cart.min.js

To increase the CheckOut loader icon: /wp-content/plugins/woocommerce/assets/js/frontend/checkout.min.js

Search for 16px and change them to 128px. If you upgrade WooCommerce these changes are going to be lost :) so change them again! :)

čtvrtek 11. února 2016

Cleaning JavaScript Malware On Your Linux Server (Removing Javascript Between Two Points)

So, I think everyone has faced this issue who has an own VPS server. Our problem was that sometimes every or some of JS files got infected. It can be a mass to delete the malware code from the files manually.

So with the help of this article I have created my own code: Linux Academy

The problem was that this code worked when the exploit code has began and ended with the same value. But our newest infection was a little bit tricky. Every JS files has a different malware comment value in it. So I cant use the code from Linux Academy anymore.

Sucuri have wroted about this infection: Link

The hackers injected encrypted code at the end of all legitimate .js files. Which seems like this (image from Sucuri):
I have struggled with this infection for a time. And I want to share my solution, which can remove this from every JS file within less then 5 seconds. Every command is called recursivily, so if you run it on public_html/ or www/ folder it will include wp-admin, wp-content, everything. The pattern in our case is a regular expression [a-z0-9]{32} means lowercase letters and numbers and exactly 32 times.

1. Search if there is a JS infection on your server, the -l switch will list only the file names
 find . -name "*.js" | xargs grep -E "\/\*[a-z0-9]{32}\*\/" -l | sort  

2. Add a new line character before the pattern, this is very important, sed can only delete lines from files upwards.
 find . -name "*.js" -exec sed -i "s/\/\*[a-z0-9]\{32\}\*\//\n&/g" '{}' \;  

3. Finally delete the malware code from all infected JS files:
 find . -name "*.js" -exec sed -i "/[a-z0-9]\{32\}/,/[a-z0-9]\{32\}/d" '{}' \;  

Before you try this please test it on one file, i have a CentOS server installed.
I have found three backdoors installed with the help of access_logs and blocked the IPs in our firewall.
/wp-content/plugins/yith-woocommerce-ajax-search/widgets/class44a.php
/wp-content/languages/admin-network-hu_HU182a1.php
/wp-cont.php

I hope this helps someone.

Regards, Peter

neděle 3. května 2015

Update Facebook Sharer Cache automatically on Page Load

So I have this problem on my one of my clients website. The Facebook cache was not updateed correctly. And no images was loaded. I know that in every 24 hour the cache is updated. But I need this to be done automatically on page load now. This solution is good for WordPress and WooCommerce too. Add this to your functions.php file and the Sharer Cache will be updated on page load.
add_action( 'wp_footer', 'fb_sharer_updater', 5 );

if(!function_exists('fb_sharer_updater')) {
    function fb_sharer_updater() {
        global $post;
            
            echo '<script type="text/javascript">
    jQuery.post(
    "https://graph.facebook.com",
    {
     id: "'.  get_permalink() .'",
     scrape: true
    },
    function(response){
     console.log(response);
    }
   );';
            echo '</script>';
            
        
    }
}
You need to wait approx 5seconds, then the new scrape info is added to FB cache. Open Developer Console and you will see additional information:
Object {url: "http://theblackcat.sk/produkt/plazove-saty-texas-s-5995/", type: "article", title: "Plážové šaty Texas S-5995 - TheBlackCat.sk", locale: Object, image: Array[1]…}
description: "Ľahučké plážové šaty so vzorom, s viazaním na boku. Plážové šaty odporúčame ku všetkým bikinám Texas 2015 ako doplnka."
id: "1532012490185775"
image: Array[1]
locale: Object
site_name: "TheBlackCat.sk"
title: "Plážové šaty Texas S-5995 - TheBlackCat.sk"
type: "article"
updated_time: "2015-05-03T14:23:15+0000"
url: "http://theblackcat.sk/produkt/plazove-saty-texas-s-5995/"
__proto__: Object

sobota 31. ledna 2015

Adding TinyCon library to WooCommerce - Show products in cart count on the favicon

I just came across with a solution for implementing TinyCon with WooCommerce. I use this super-easy, leightweight library to display cart quantity on the favicon.

You need to edit file footer.php in your theme, you find this in most cases:

    /wp-content/themes/xxxxxx/footer.php

What you need to add first is the TinyCon JS library. Download it from [Github][1].

Then you need to call this library and add the cart quantity to display it on the favicon. Add this code before the </body> tag.

My code with explanation:

 <?php global $woocommerce;  //you need this for het the cart quantity
    $my_cart_count = $woocommerce->cart->cart_contents_count; //get the quantity
    ?>
     <script src="<?php bloginfo('stylesheet_directory'); ?>/includes/js/tinycon.min.js" type="text/javascript"></script> //call the TinyCon library
     <script type="text/javascript">
    Tinycon.setOptions({
        width: 7,
        height: 9,
        font: '10px arial',
        colour: '#ffffff',
        background: '#e01c1f',
        fallback: true
    });
     </script>
    <?php if ($my_cart_count > 0) :             //if cart has products in it display bubble by default.
    ?>
    <script type="text/javascript">
   
    Tinycon.setBubble(<?php echo $my_cart_count; ?>);
   
    </script>
    <?php
    endif;
    ?>
    // this part is needed if you use AJAX add to cart in WooCommerce, this will ensure when if you click on AJAX add to cart button the bubble is updated correctly.
    <script type="text/javascript">
     var darab =  <?php echo $my_cart_count; ?>;
     
     jQuery('.add_to_cart_button').bind('click',function() {
       
     darab = darab + 1 ;
     
     Tinycon.setBubble(darab); 
    });
   
    </script>


  [1]: https://github.com/tommoor/tinycon

čtvrtek 15. ledna 2015

WooCommerce + WordPress new line issue with Mandrill

As I stated in previous topic after installing Mandrill my WordPress text/plain emails doesnt contain new line breaks, because they are coded with /n/r code.

There is an option in settings of Mandrill, that you can:
Replace all line feeds ("\n") by <br/>in the message body?

But if you enable this the WooCommerce emails are going to be ugly, because they are already HTML emails, not just plain text emails, which are sended out by WordPress by default.

To solve the issue you need to use the mandrill_playload hook which is just fired before an email sents out.
add_filter('mandrill_payload', 'customFilterName');
 More about this filter: http://blog.mandrill.com/own-your-wordpress-email-with-mandrill.html

What you need to do is select the type of emails with tags which are plain/text emails only.

You need to get the tags from your Mandrill admin.


As you can see, these are the tags in my case.

The wp_WC_Email->send work just fine, because this is the tag for WooCommerce store emails, these are coded with text/html.

What I needed to add is: wp_userpro_mail, wp_template-contact.php and wp_wp_new_user_notification, because these are encoded only in text/plain.

To bypass this and insert correct line breaks tags you just to need to add the following to your functions.php in your theme.

 /*************************************************************************/
 /*WPMandrill playload, add <br> to emails*/
 /*************************************************************************/
 function wd_mandrill_woo_order( $message ) {
      $tags = $message['tags']['automatic'];
   if ( (in_array( 'wp_template-contact.php', $tags )) || (in_array( 'wp_userpro_mail', $tags )) || (in_array( 'wp_wp_new_user_notification', $tags )) ) {
     $message['html'] = nl2br( $message['html'] );
   }
   return $message;
 }
 add_filter( 'mandrill_payload', 'wd_mandrill_woo_order' );

The key functions here is the nl2br which just returns string with '<br />' or '<br>' inserted before all newlines (\r\n, \n\r, \n and \r).

After this little code snippet every system emails from WordPress are correctly displayed :)))

Maybe someone is facing the same issue and I helped him with this :).