Home Blog

Import and export mySQL databases


So i have a 300MB database and it is real hard to import it with phpMyAdmin or other web based software.

This is why i want to do it with the simple linux command.

How can you do that?

Import a mysql database

After you created the database you need to put the following command:

mysql -u username -p new_database < /path/fo/file.sql

After you execute the file it will ask you the user mysql password.

Export a mysql database

Mysql export is very easy. For this you need to use the following command:

mysqldump -u username -p database_name > /path/to/file.sql

After you run this it will ask also for your password.

Remove link from the image on product single page on WooCommerce


Working on a different WooCommerce site got me to do a lot of customisation. I recently need it a way to remove the link from main image or a product from the single product page.

This can be done by changing some code on WooCommerce templates but i wanted to do it another way. Here is the solution i found. Put the following code into the functions.php file for your theme:

function dex_remove_product_image_link( $html, $post_id ) {
    return preg_replace( "!<(a|/a).*?>!", '', $html );
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'dex_remove_product_image_link', 10, 2 );

Remove hover effect on single product on WooCommerce


I tried multiple ways to remove the hover effect on the single product page on WooCommerce products but most of them did not work.

I found a good sollution here:

function dex_remove_image_zoom_support() {
    remove_theme_support( 'wc-product-gallery-zoom' );
add_action( 'wp', 'dex_remove_image_zoom_support', 100 );

You can put this code into you functions.php of your theme and this effect should be off.

thanks and best wishes

Add a new required checkbox for privacy before order


If you need a new checkbox after the term & conditions on WooCommerce orders you can easily do this by adding the following code:

add_action( 'woocommerce_review_order_before_submit', 'dex_add_checkout_privacy_policy', 9 );
function dex_add_checkout_privacy_policy() {
        woocommerce_form_field('privacy_policy', array(
            'type' => 'checkbox',
            'class' => array('form-row privacy'),
            'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkboxship checkbox'),
            'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
            'required' => true,
            'label' => 'Text for the checkbox--this needs to be changed',

add_action( 'woocommerce_checkout_process', 'dex_not_approved_privacy' );

function dex_not_approved_privacy() {
    if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
        wc_add_notice( __( 'Please acknowledge the terms and conditions' ), 'error' );

Add metas to Re-order on WooCommerce


When you do an re-order on WooCommerce it seems that the system does not copy all of the meta values added by you in the first order.

So i had a site that added some meta fields and when somebody reorder i did not found what meta data it was used. I figure out that when reorder the system does not copy all meta info. I fixed this with a simple function:

add_filter( 'woocommerce_order_again_cart_item_data', 'dex_order_again_cart_item_data', 10, 3 );

function dex_order_again_cart_item_data($cart_item_meta, $product, $order){
    //Create an array of all the missing custom field keys that needs to be added in cart item.
    $customfields = [
        'metakey1added', 'metakey2added',
    global $woocommerce;
    remove_all_filters( 'woocommerce_add_to_cart_validation' );
    if ( ! array_key_exists( 'item_meta', $cart_item_meta ) || ! is_array( $cart_item_meta['item_meta'] ) )
        foreach ( $customfields as $key ){
                $cart_item_meta[$key] = $product[$key];
    return $cart_item_meta;

The script will copy all of the meta to the current order. For my site this works like a charm.

Do not allow PO BOX address to be used on shipping for Woocommerce


I had a task from a client to make a script not to allow shipping to PO BOX address from Woocommerce.

This can be done by using and adding the following code on functions.php on the theme folder. I recommend using always a child theme if you do regular updates to the theme:

add_action('woocommerce_after_checkout_validation', 'deny_pobox_postcode_function');

function deny_pobox_postcode_function( $posted ) {
    global $woocommerce;

    $address  = ( isset( $posted['shipping_address_1'] ) ) ? $posted['shipping_address_1'] : $posted['billing_address_1'];
    $postcode = ( isset( $posted['shipping_postcode'] ) ) ? $posted['shipping_postcode'] : $posted['billing_postcode'];

    $replace  = array(" ", ".", ",");
    $address  = strtolower( str_replace( $replace, '', $address ) );
    $postcode = strtolower( str_replace( $replace, '', $postcode ) );

    if ( strstr( $address, 'pobox' ) || strstr( $postcode, 'pobox' ) || strstr( $address, 'p.o. box' ) || strstr( $address, 'po box' ) || strstr( $address, 'po. box' ) ) {
        wc_add_notice( sprintf( __( "We cannot ship to PO BOX addresses.") ) ,'error' );

Get full list of posts/pages for one author


The following short code will help you get all posts from a current logged user.

$args = array(
            'post_type' => 'post', // this can be changed to any(for all), page(for pages) or other custom post type
            'posts_per_page' => '-1',
            'post_status' => 'publish', //this status will take only published posts. You can use any status
$my_query = new WP_Query($args);

If you wish to get a specific user posts just use the following code:

$args = array(
            'post_type' => 'post', // this can be changed to any(for all), page(for pages) or other custom post type
            'posts_per_page' => '-1',
            'post_status' => 'publish', //this status will take only published posts. You can use any status
            'author'=>[id of the user] // replace [id of the user] with the ID number of user
$my_query = new WP_Query($args);

You can also use the Author name to get all users posts. This is the code for this:

$args = array(
            'post_type' => 'post', // this can be changed to any(for all), page(for pages) or other custom post type
            'posts_per_page' => '-1',
            'post_status' => 'publish', //this status will take only published posts. You can use any status
            'author_name'=>'[name of the user]' // replace [name of the user] with the username of user
$my_query = new WP_Query($args);

How to restore a user on VestaCP


After you have backup up your users on VestaCP you can easily restore them. Please note if you have backedup your user with cPanel or other system this tutorial will not work.

First of all please copy the archives on path /backup/.

After that the following command will help you to restore a user in VestaCP is:

v-restore-user user nameofarchive.tar

So lets say we want to restore user mmm with archive name mmm.2019-06-07_10-05-58.tar. The command will look like this:

v-restore-user mmm mmm.2019-06-07_10-05-58.tar

Please note: from what i have seen you need to use the same username as on the old server. The system will give you an error if you wish to change the username into something new. If i exported user mmm i need to import the same user mmm. It will not allow me to change the username as something else.

How to backup all users on VestaCP


I use VestaCp for lots of my servers on DigitalOcean. I will make a new posts that will explain what commands i use on this system.

When you wish to transfer a website account or you just wish to backup your sites i use the following command:


This command will create a backup for all users on VestaCp and will create the archive on folder /backup/ on the server(if you did not add a custom backup path).

How to check what devices wakes up the computer from sleep mode


I usually do not power off my computer but put it in sleep mode or hibernate.

The best thing about this is you have all your software opend and you do not need to stay much time to see what you were doing before you stopped working.

But on my workstation i just reinstalled my Windows and in the morning i always find my PC already on. What can you do to fix this issue?

Simple: you just need to run the bellow command:

powercfg -devicequery wake_armed

Anfter you have run this command you will see a list of devices that wakes up your PC.

You need then to go to Device manager, find those devices and unselect the option from Power Management: Allow this device to wake the computer.

After you have finished the list you can run again the command to see if the result is NONE. If that is the case then you are done:)