E-commerce Code Snippets

Here you'll find some snippets to do some general common stuffs in Themify ecommerce themes. Note that some snippets might not work in all themes.

General procedure to use a snippet

1. Create a child theme and a functions.php file in the child theme folder if you don't have it yet.

2. Edit the child theme functions.php and paste the code snippet as you want. If you encounter any error, undo or remove the code snippet.


<?php

// Snippet code goes here

?>

3. If you already have existing PHP function in the child theme functions.php file, you only need to add the PHP code inside the <?php and ?> tags.


<?php

/**
 * Replace default link that adds product to cart with a link to product single view labeled Read More
 * @param $html
 * @param $product
 * @param $link
 * @return string
 */
function custom_themify_woocommerce_loop_add_to_cart_link( $html, $product, $link ) {
	return sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button product_type_%s">%s</a>', get_permalink( $product->id ), esc_attr( $product->id ), esc_attr( $product->get_sku() ), esc_attr( $product->product_type ), __('Read More', 'themify') );
}
add_filter('woocommerce_loop_add_to_cart_link', 'custom_themify_woocommerce_loop_add_to_cart_link', 10, 3);

?>

Read More

Entering FTP Information for Faster Upgrades

If your site has restricted access to PHP routines for file reading and writing and only allows it by FTP or other method, this might conflict with the theme or framework upgrade. In these cases, you can try entering the ftp access info in the wp-config.php to bypass the FTP connection information prompt.

For these steps you should use an FTP software to access your server files:

  1. open wp-config.php located in the site root folder
  2. find the line
    
    if ( !defined('ABSPATH') )
    
  3. before this line, paste this snippet:
    
    define( 'FS_METHOD', 'ftpext' );
    define( 'FTP_SSL', false );
    define( 'FTP_BASE', '/your-wordpress-root/' );
    define( 'FTP_CONTENT_DIR', '/your-wordpress-root/wp-content/' );
    define( 'FTP_PLUGIN_DIR', '/your-wordpress-root/wp-content/plugins/' );
    define( 'FTP_USER', 'ftp_username' );
    define( 'FTP_PASS', 'ftp_password' );
    define( 'FTP_HOST', 'ftp.yourdomain.com' );
    
  4. replace
    
    '/your-wordpress-root/'
    

    with the server path to your WordPress installation. Typically, you might have installed WordPress in your root folder. so you would use

    
    define( 'FTP_BASE', '/' );
    define( 'FTP_CONTENT_DIR', '/wp-content/' );
    define( 'FTP_PLUGIN_DIR', '/wp-content/plugins/' );
    
  5. replace ftp_username, ftp_password and ftp.yourdomain.com with the correct keys. You should have got these from your hosting provider.
  6. once you've filled-in all the info. Save the wp-config.php file.

It's ready now, so next time you try to upgrade, you won't have to enter the credentials.

Read More

Using WordPress 3.6’s own video shortcode

If you wish to use the [video] shortcode included in WordPress 3.6 instead of Themify's own video shortcode, you can follow these steps:

1. Create a file named custom-functions.php in your theme root folder
2. Edit it, and paste the following


<?php
remove_shortcode( 'video' );
add_shortcode( 'video', apply_filters( 'wp_video_shortcode_handler', 'wp_video_shortcode' ) );
?>

3. Save the file. If you were editing it locally, upload it by FTP to the theme folder in your server.
4. in WP Admin, go to Themify > Styling > Custom CSS
5. paste this


.mejs-container, .wp-video-shortcode {
    max-width: 100% !important;
}

6. save and check your site.

Read More

Disabling Theme Upgrader

As of Framework 4.2.5, Themify upgrader function has been removed in the framework. This tutorial is no longer relevant if you are using any Themify theme with framework 4.2.5+. All Themify themes and plugins can be auto upgraded/installed using Themify Updater plugin.

The following code will prevent checking for Themify theme upgrades so upgrade notices will no longer be displayed:

  1. Create a file named custom-functions.php in the Themify theme root folder (if it doesn't exist)
  2. Paste the following code
    
    <?php
    
    define('THEMIFY_UPGRADER', false);
    
  3. Save the file. If you were editing the file locally, upload it to your server by FTP.

Disabling updates for Builder addons

This will disable the autp update functionality for all Builder addons:


<?php

add_filter( 'themify_builder_updater_enabled', '__return_false' );

To disable it only for particular addons you can use:


<?php

function custom_disable_builder_updater( $enabled, $name, $update_type ) {
	$disabled = array( 'builder-image-pro', 'builder-timeline' );
	if( in_array( $name, $disabled ) ) {
		$enabled = false;
	}

	return $enabled;
}
add_filter( 'themify_builder_updater_enabled', 'custom_disable_builder_updater', 10, 3 );

Read More

Open External Links in New Window

To open everything in new window, this code can be added in Themify > Settings > General => Header Code:


<base target="_blank" >

Apply to post external links

To open all external links in the post in a new tab, follow these steps:

1. go to Themify > Settings > General
2. in the Footer Code box, paste this


<script type="text/javascript">// <![CDATA[
jQuery(document).ready(function($){
    $('.post')
      .find('a[href]:not([href^="https://themify.me"]):not([href^="#"]):not([href^="/"])').attr( 'target', '_blank' );
});
// ]]></script>

3. In the snippet above replace "https://themify.me" with the URL of your own site. Now save and check the site.

Apply to all external links

If you instead want to open all the external links (in content, sidebar, header, footer, etc.) in a new tab, use this code:


<script type="text/javascript">// <![CDATA[
jQuery(document).ready(function($){
    $('a[href]:not([href^="https://themify.me"]):not([href^="#"]):not([href^="/"])').attr( 'target', '_blank' );
});
// ]]></script>

In the snippet above replace "https://themify.me" with the URL of your own site.

Using Plugin

Alternatively, you can use a third party to open external links in a new window - check this plugin.

Read More

Disabling Google Fonts

If you need to disable the Google Fonts list in the Builder and WP Customize (eg. server can not load the fonts or performance issues), you can disable it with the following methods:

Method 1) Themify Panel

Go to Themify > Settings > General -> Google Fonts, select disable Google Fonts option

Method 2) Child Theme

If you need to disable the Google Fonts list in the Builder and WP Customize (eg. server can not load the fonts or performance issues), you can disable it with the following custom function.

  • Create a child theme and a functions.php file (if it doesn't exist)
  • Paste in the following function:

<?php
	// disable Google fonts
	add_action( 'after_setup_theme', 'theme_disable_google_fonts', 1 );
	function theme_disable_google_fonts() {
		define('THEMIFY_GOOGLE_FONTS', false);
	} 
?>

Read More

Themify 7.5 has released! Please read the update notes.