How to activate drift message box?

Hello Guys,

Today I will be sharing my experience on activating drift message box after certain specific time. I had achieved this by using javascript setTimeout() function. You can paste this code on theme custom js file or can use add_inline_script() function to add this script.

var showwelcome_msg = function () {
    setTimeout( function() { 
    	drift.on('ready', function(api, payload) {
    		api.showWelcomeMessage();
    	    
    	});
    }, 90000 );
    
}
window.onload = showwelcome_msg;

 

This above code will open drift message box after 90sec of page load , you can change time as per your requirement.

Let me know if you have any question or queries or any other best solution.You can ping me on adhsushil7@gmail.com

Best Regards
Sushil Adhikari

Advertisements

WooCommerce downloadable links lost?

Tags

, , , ,

downloadable-product-overview

Hello Everyone, Today I am going to share my experience of debugging WooCommerce download links which was lost after the transferring the host. Actually transferring the host  sometimes broke the serialised data and in our case serialised value of   _downloadable_files  meta key was broken. After detecting the issue was from broken serialised data I went to take help of plugin below which doesn’t help me on this case, So I went on development of module which will fix this error:

Note: Please keep backup of your database before applying this method

Plugins I tested with:

Please copy the codes below on to your theme functions.php file and saved it.

/**
* correct broken serialized data of woocommerce download meta data
*/
$args = array(
	'post_type' => 'product',
	'posts_per_page' => -1,
	'meta_key' => '_downloadable_files',
	'fields' => 'ids'
);

$product = get_posts( $args );
foreach ($product as $key => $product_id ) {
	$post_meta = get_post_meta( $product_id ); 
	$coorected_serialized_data = $post_meta[ '_downloadable_files' ];
	$unserialize = unserialize( themeslug_serialize_corrector( $coorected_serialized_data[0] ) );
	if( $unserialize  ) {
               //Comment out this loop if your server doesn't support SSL or you do not want to change your download links to https:
		foreach ($unserialize as $hash_key => $file_details ) {
			$file_details[ 'file' ] = esc_url_raw( preg_replace( '/http/', 'https', $file_details[ 'file' ] ) );
			//construct array
			$final_meta_value = array(
				$hash_key => $file_details
			);
		}
		
		//array variable will be automatically serialized before saving on to database.
		update_post_meta( absint( $product_id  ), '_downloadable_files', $unserialize  );
	}
	
}
/** 
* @return corrected serialised string 
*/
function themeslug_serialize_corrector($serialized_string){
    // at first, check if "fixing" is really needed at all. After that, security checkup.
    if ( @unserialize($serialized_string) !== true &&  preg_match('/^[aOs]:/', $serialized_string) ) {
         $serialized_string = preg_replace_callback( '/s\:(\d+)\:\"(.*?)\";/s',    function($matches){return 's:'.strlen($matches[2]).':"'.$matches[2].'";'; },   $serialized_string );
    }
    return $serialized_string;
}

Note: This code was tested with website of 50 products, So I highly encourage you to use cron job to implements this code on large store. Also please remove the code after the use.

Let me know if you have any question or queries or any other best solution.You can ping me on adhsushil7@gmail.com

Best Regards

How to use widget as a shortcode?

Hi Everyone,

Today I will be sharing my experience on building shortcode from registered widgets. I had developed this feature on Styled Store Pro making all the custom widgets available as shortcode. A shortcode can be very useful on using the dynamic content on post/pages content and text widgets.

I hope you guys know how to build custom widgets and shortcode. If not please go through these link:
Widgets API
Shortcode API

Here our logic is to developing shortcode calling the_widgets() template tags on our shortcode callback function. the_widgets() accepts the instance which we will be sending as shortcode parameter. So let’s use default WordPress recent posts widgets on the shortcode
Continue reading

Image

How to Add Metabox On Houzez Child Theme ?

houzez-preview

Hello everyone,
Today I am going to share my experience while adding metabox on child theme using metabox.io on Houzez child Theme
Houzez Theme use metabox.io plugin to create metabox field on custom post type property as well default WordPress Post type. While using “”rwmb_meta_boxes” filter hook on child theme I came to lost all the metafield created by Houzez Parent Theme. So I start to dig on the code and found that houzez theme provides “houzez_theme_meta” to extend metabox field. You can see this filed on this template:

houzez -> frameworkd -> metabox -> houzez-meta-boxes.php.

Continue reading

Image

How to use wp_dropdown_categories() on widget field?

usingwidgets

Hello Guys,

Let’s see how we can implement wp_dropdown_categories() on widget field.

Here I am implementing codex way of making widgets: see here for reference: https://codex.wordpress.org/Widgets_API

You can see more about wp_dropdown_categories() here: https://codex.wordpress.org/Function_Reference/wp_dropdown_categories

So here we go-> Continue reading

Image

How to crop image in customizer image field ?

theme-customization

Hello everyone,

Today I am going to illustrate on , how to cropped image on customizer.

Normally we use WP_Customize_Image_Control for selecting image on customizer section, but this doesn’t provide you the featured to cropped image on your requirement.
But WordPress provide us class called ‘WP_Customize_Cropped_Image_Control‘ which provide you the featured to crop a image.You can see full code here: https://core.trac.wordpress.org/browser/tags/4.6/src/wp-includes/customize/class-wp-customize-cropped-image-control.php#L17
Before starting the tutorial I hope you all guys know how to add section, setting and control on customizer.
Step 1: First create section: Continue reading