Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to overwrite functions written in woocommerce-functions.php file

I want to modify/overwrite functions written in woocommerce-functions.php file but I don't want to modify woocommerce-functions.php file. That is I want to achieve this in plug-in or in my theme.

like image 732
Naresh Walia Avatar asked Jan 28 '14 05:01

Naresh Walia


2 Answers

It is possible to override woocommerce functions, I did this recently and added all of my woocommerce extended functionality to my theme's functions.php file so that the woocommerce plugin files remained untouched and are safe to update.

This page gives an example of how you can remove their action and replace it with your own - http://wordpress.org/support/topic/overriding-woocommerce_process_registration-in-child-theme-functionsphp

This page gives an example of extending upon their functions without removing their function, as well as using child themes - http://uploadwp.com/customizing-the-woocommerce-checkout-page/

Hope this helps :)

like image 118
flauntster Avatar answered Sep 18 '22 18:09

flauntster


WooCommerce provides a templating system. It is possible to override woocommerce functions. great way to customize WooCommerce without modifying core files, is to use hooks -

If you use a hook to add or manipulate code, you can add your custom code to your theme functions.php file.

  • Using action hooks -

To execute your own code, you hook in by using the action hook do_action(‘action_name’);.

See below for a great example on where to place your code:

add_action('action_name', 'your_function_name');

function your_function_name() 
{
// Your code
}
  • Using filter hooks-

Filter hooks are called throughout are code using apply_filter(‘filter_name’, $variable);

To manipulate the passed variable, you can do something like the following:

add_filter('filter_name', 'your_function_name');

function your_function_name( $variable )
 {
// Your code
return $variable;
}

Here you can get WooCommerce Action and Filter Hook - https://docs.woothemes.com/wc-apidocs/hook-docs.html

like image 41
Swapnali Avatar answered Sep 21 '22 18:09

Swapnali