I am using Wordpress 4.6 with WooCommerce 2.6.4 and Smart Coupon 3.1.2 plugin.
I would like to move the "available coupons" section from the top of my checkout page to the bottom.
In the plugin file I've detected this structure and the action that I need to change.
I need to change it to 'woocommerce_after_checkout_form' but I can't get my head around on how to override it from the functions.php file.
I've already tried directly from the plugin to change it and it works like I would but we all know that it's a wrong approach to edit a plugin's behaviour.
Any help and documentation would be really helpful.
class WC_Smart_Coupons {
...
public function __construct() {
...
add_action( 'woocommerce_before_checkout_form', array( $this, 'show_available_coupons_before_checkout_form' ), 11 );
...
}
}
...
function initialize_smart_coupons() {
$GLOBALS['woocommerce_smart_coupon'] = new WC_Smart_Coupons();
}
add_action( 'plugins_loaded', 'initialize_smart_coupons' );
So, I had similar problem today. You can do following to move that section to different place.
To remove:
remove_action( 'woocommerce_before_checkout_form', array( $GLOBALS['woocommerce_smart_coupon'], 'show_available_coupons_before_checkout_form' ), 11 );
To add:
add_action( 'any_action', array( $GLOBALS['woocommerce_smart_coupon'], 'show_available_coupons_before_checkout_form' ), 11 );
The accepted solution doesn't work for the Smart Coupons version I use (4.12.2).
To change the "available coupons" position use the following instead:
$obj_inst = WC_SC_Display_Coupons::get_instance();
remove_action( 'woocommerce_before_checkout_form', array( $obj_inst, 'show_available_coupons_before_checkout_form' ), 11 );
add_action( 'woocommerce_checkout_after_customer_details', array( $obj_inst, 'show_available_coupons_before_checkout_form' ), 11 );
A nifty visual list of woocommerce checkout page hooks can be found here.
Related
I am trying to allow the usage of decimal quantities in the admin panel.
I had added the following code:
remove_filter( 'woocommerce_stock_amount', 'intval' );
add_filter( 'woocommerce_stock_amount', 'floatval' );
But when I edit the order and try to change the quantity to decimals, after hitting update order, nothing happens and the following error comes in the console:
An invalid form control with name='order_item_qty[328]' is not focusable.
(328 is the item I Tried to edit)
Any solutions for this?
Ok I found the answer after digging in some Woocommerce Core Files:
Instead of using this:
add_filter( 'woocommerce_quantity_input_step', array( &$this, 'min_decimal' ), 99 );
I used this:
if(is_admin()){
add_filter( 'woocommerce_quantity_input_step', array( &$this, 'admin_qty_step' ), 99 );
}
else{
add_filter( 'woocommerce_quantity_input_step', array( &$this, 'min_decimal' ), 99 );
}
While the min_decimal method returns a string with a preset quantity step on the front-end and admin_qty_step returns "0.1" on the Back-end Interfaces.
Hope someone find this helpful
I'm currently trying to remove all messages from the WooCommerce account with the following code line:
remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 10 );
Sadly, the wrapper for messages is still there:
<div class="woocommerce-notices-wrapper">lol</div>
I've added a lol to the function that displays the wrapper and it's the correct function I'm trying to remove. No idea why it's not working...
If your active theme uses the default woocommerce templates and hooks for myaccount pages, then add the follows code snippet to achieve the above -
function modify_wc_hooks() {
// remove all wc my account's notices wrapper
remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 5 );
remove_action( 'woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10 );
remove_action( 'woocommerce_before_lost_password_form', 'woocommerce_output_all_notices', 10 );
remove_action( 'before_woocommerce_pay', 'woocommerce_output_all_notices', 10 );
remove_action( 'woocommerce_before_reset_password_form', 'woocommerce_output_all_notices', 10 );
}
add_action( 'init', 'modify_wc_hooks', 99 );
Codes goes to your active theme's functions.php
I'm working on a Woocommerce site that is using the following plugin: https://docs.woothemes.com/document/woocommerce-order-delivery/ ("WooCommerce Order Delivery")
The plugin is now displayed on the Checkout page under the billing fields in the checkout_shipping section, I am trying to change this location to the checkout_order_review section by hooking in to the functions.
But I can't seem to get it working.
My code in my functions.php:
function action_woocommerce_checkout_shipping( $instance ) {
global $woocommerce;
if ( is_checkout() && $woocommerce->cart->needs_shipping() ) {
echo 'Hi World!';
if ( wc_od() ){
echo 'Found wc_od function';
}
remove_action( 'woocommerce_checkout_shipping', 'checkout_content' );
}
};
// add the action
add_action( 'woocommerce_checkout_shipping', 'action_woocommerce_checkout_shipping' );
My thought behind this code was that I remove the function 'checkout_content' which retrieves the plugin template and then add the action to the woocommerce_checkout_order_review function to display it in the order review section.
But my remove_action doesn't seem to work.
The code in the plugin that adds the checkout_content action:
protected function __construct() {
// WP Hooks.
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
// WooCommerce hooks.
add_action( 'woocommerce_checkout_shipping', array( $this, 'checkout_content' ), 99 );
add_action( 'woocommerce_checkout_process', array( $this, 'validate_delivery_date' ) );
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'update_order_meta' ) );
// Delivery date validation hooks.
add_filter( 'wc_od_validate_delivery_date', array( $this, 'validate_delivery_day' ), 10, 2 );
add_filter( 'wc_od_validate_delivery_date', array( $this, 'validate_minimum_days' ), 10, 2 );
add_filter( 'wc_od_validate_delivery_date', array( $this, 'validate_maximum_days' ), 10, 2 );
add_filter( 'wc_od_validate_delivery_date', array( $this, 'validate_no_events' ), 10, 2 );
}
Can someone maybe give me a push in the right direction?
Am I doing this wrong ? or is there a better way of achieving this?
You have two issues.
Firstly you need to specify the execution priority when you remove action, or at least you do when it is anything other than the default, 10. In your case the execution priority is 99.
Secondly, checkout_content() is a class function, not a standalone function so you need to specify this in the function reference.
So your remove_action line of code will be:
remove_action( 'woocommerce_checkout_shipping', array( $the_class_variable, 'checkout_content' ), 99 );
where $the_class_variable is the instance of the class containing that __construct() function. How you refer to this depends on how the class has been instantiated in the plugin.
You can read about different ways of instantiating a class and the corresponding remove_action at http://jespervanengelen.com/different-ways-of-instantiating-wordpress-plugins/
You can read about remove_action this in https://codex.wordpress.org/Function_Reference/remove_action
I'm developing a plugin to customise the woocommerce registration and trying to avoid direct editing of the core files.
I need to override or replace process_registration action in woocommerces includes/class-wc-form-handler.php file through my plugin.
add_action( 'init', array( $this, 'process_registration' ) );
I tried following links, but they didn't work. Also, the files mentioned on those pages doesn't exist on woocommerce current version. I also checked woocommerce documentation, but it seems they don't have a hook for that.
http://wordpress.org/support/topic/overriding-woocommerce_process_registration-in-child-theme-functionsphp
Woocommerce Hooks:
http://docs.woothemes.com/document/hooks/
I'd really appreciate any help!
Two options for that and considering that WC method starts like:
class WC_Form_Handler
public function __construct() {
add_action( 'init', array( $this, 'process_registration' ) );
}
public function process_registration() {
if ( ! empty( $_POST['register'] ) ) {
wp_verify_nonce( $_POST['register'], 'woocommerce-register' );
# etc
}
}
}
new WC_Form_Handler();
Add an init hook with top priority and duplicate then unset($_POST['register']). WC doesn't specify a priority, so it's running on 10, which is default.
add_action( 'init', function() { /* dup, unset, do your thing */ }, 1 ); // priority 1
Track down that evil anonymous object where Woo is hidding its hook, so that you can:
// pseudo code, go to WPSE for the real thing
remove_hook( 'init', 'woo_process_registration' );
I'm doing a custom payment plugin for Woocomerce.
I need remove the detail of order by "/checkout/order-received/", ie I want remove "Order Details", "Customer details" and "Billing Address".
I had put in my plugin:
remove_action( 'woocommerce_view_order', 'woocommerce_order_details_table' );
but it doesn't work. I've also put in INI , but it still doesn't work.
function gowc_process_init() {
remove_action( 'woocommerce_view_order', 'woocommerce_order_details_table' );
}
add_action('init', 'gowc_process_init');
Could you help me with this topic, please?
PD: Remember that is a plugin, don't is a theme.
Ok, found the solution.
remove_action( 'woocommerce_view_order', 'woocommerce_order_details_table', 10 );
remove_action( 'woocommerce_thankyou', 'woocommerce_order_details_table', 10 );