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);

?>