How To Make WordPress Theme Multilingual and WooCommerce Compatible

Woocommerce + WPML + Anandmahalakshmi

In this article you can learn about how to create a wordpress theme which is perfectly suitable for Woocommerce and WPML.

Before starting i would like to mention some points.

In order to have a multilingual woocommerce website you need to install the following plugins.

Woocommerce By Woothemes – https://wordpress.org/plugins/woocommerce/

WPML By OnTheGoSystems,Inc. – (http://wpml.org/)

Woocommerce Multilingual – (https://wordpress.org/plugins/woocommerce-multilingual/)

WPML allows you to translate all the standard WordPress elements. This includes:

  • Menus
  • Standard widgets
  • Navigation elements
  • All texts wrapped in `gettext` calls
  • Post content including custom fields and taxonomy
  • Products
  • Theme options
  • Images and strings related to them

In order to have a WPML supported theme, you must follow the below conditions.

Add GetText Functions to Texts

For plugins or themes, be sure to wrap your hard-coded text in `gettext` functions. This includes the header, footer, and widget text. Your template files display an assortment of product information and hard coded text. For example, most templates will include the product name and a ‘buy’ link. The product name comes from the database, so you don’t need to worry about translating it.
Continue Reading…

Woocommerce – add products automatically to cart on visit

woothemes-ninja-logo-brand

Today i am going to share one of the feature which my client asked to me, and that is to add the product automatically once the visitor viewed that product. Hope this will help someone who is having requirement like this.

* To be added on theme's functions.php or a custom plugin
// add products automatically to cart on visit
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 64;
$found = false;
//check if product already in cart
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->id == $product_id )
$found = true;
}
// if product not found, add it
if ( ! $found )
$woocommerce->cart->add_to_cart( $product_id );
} else {
// if no products in cart, add it
$woocommerce->cart->add_to_cart( $product_id );
}
}
}

Solving get_available_shipping_methods() method errors

woothemes-ninja-logo-brand

The error looks something like this (the full path and line number may be different):

Fatal error: Call to undefined method WC_Shipping::get_available_shipping_methods() in .../wp-content/themes/THEME-NAME/woocommerce/checkout/review-order.php on line 14

This issue is caused by your theme, they are bundling outdated template files in their themes that have been deprecated for a while now. You should contact the theme developer to get this fixed properly. You can delete that specific file from your theme until this issue has been patched by your theme developer for a temporary fix. WooCommerce will fall back on the default template file, bundled with the plugin.

Variable products won’t add to cart – Woocommerce Upgrade Issue

woothemes-ninja-logo-brand

I have seen that still there some theme having bundled with old files for the add to cart template being used for variable products, adding a variable product to cart fails. This should be solved by the theme developers by updating the template file.

In order to solve this woocommerce upgrade issue, the quick solution is to delete the below mentioned file from the theme directory.

/woocommerce/single-product/add-to-cart/variable.php

This will make WooCommerce use the new bundled template file and your variable products will add to cart again. Once your theme developer updates your theme, please check if it actually works as that will overwrite this change again.

How to change the Add to cart message

woothemes-ninja-logo-brand
/**
 * Custom Add To Cart Messages
 * Add this to your theme functions.php file
 **/
add_filter( 'woocommerce_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
	global $woocommerce;
 
	// Output success messages
	if (get_option('woocommerce_cart_redirect_after_add')=='yes') :
 
		$return_to 	= get_permalink(woocommerce_get_page_id('shop'));
 
		$message 	= sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('Continue Shopping &rarr;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
 
	else :
 
		$message 	= sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart &rarr;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
 
	endif;
 
		return $message;
}

How to disable Woocommerce tab feature

 /**
 * Remove product tabs
 *
 */
function woo_remove_product_tab($tabs) {

    unset( $tabs['description'] );      	// Remove the description tab
    unset( $tabs['reviews'] ); 			// Remove the reviews tab
    unset( $tabs['additional_information'] );  	// Remove the additional information tab

 	return $tabs;
 
}
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tab', 98);

Set CC mail to Woocommerce

 /**
 * WooCommerce Extra Feature
 * --------------------------
 *
 * Add another email recipient to all WooCommerce emails
 *
 */
function woo_cc_all_emails() {
  return 'Bcc: youremail@yourdomain.com' . "\r\n";
}
add_filter('woocommerce_email_headers', 'woo_cc_all_emails' );

Change the add to cart text on Woocommerce

/**
 * Change the add to cart text on single product pages
 */
function woo_custom_cart_button_text() {
	return __('My Button Text', 'woocommerce');
}
add_filter('single_add_to_cart_text', 'woo_custom_cart_button_text');

/**
 * Change the add to cart text on product archives
 */
function woo_archive_custom_cart_button_text() {
	return __( 'My Button Text', 'woocommerce' );
}
add_filter( 'add_to_cart_text', 'woo_archive_custom_cart_button_text' );