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
Related
I want to update the default 'Add To Cart' text to be more suitable for my website. I have created a child theme using Astra, installed it, and then on the Theme Editor in WordPress I added a new function to my functions.php file that should have done the trick
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );
function woocommerce_custom_product_add_to_cart_text() {
return __( 'Check it out', 'woocommerce' );
}
From all the examples online it should be this easy. I just read from another post that this may be deprecated now? Should this still work, anything else I can check? I want this to be the button text globally on all products but each product still shows 'Add To Cart'. I saved and then reloaded my website but do not see any changes
add_filter( 'woocommerce_product_add_to_cart_text', 'mujuonly_add_to_cart', 10, 2 );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'mujuonly_add_to_cart', 10, 2 );
function mujuonly_add_to_cart( $text, $class ) {
return __( 'Check it out', 'woocommerce' );
}
Tested OK with WC 4.9
I need to move the Product Meta content from under the "Add to Cart" button to the "Additional Information" Tab, I want it to display similar to the attribute as the client wants to move this information to Additional Information Tab.
For eg - http://yellowbee.online/product/yellow-bee-aqua-bug-led-clogs/
I need to move the "SKU", "Categories" and "Tags" to the tab which says "Additional Information"
Website is made using xStore Theme on Wordpress & Woocommerce, I have tried reading a lot on how to achieve this but all attempts have failed.
I have tried adding the following code to the functions.php in the child theme. No Luck.
function additional_product_tabs_metabox()
{
add_meta_box(
'add_product_metabox_additional_tabs',
__( 'Additional product Tabs', 'woocommerce' ),
'additional_product_tabs_metabox_content',
'product',
'normal',
'high'
);
}
I am hoping that someone has a solution on the right code to to get this hook and then to display it in the additional information tab.
This can be done with the following:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_product_additional_information', 'woocommerce_template_single_meta', 10 );
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
This will work if the related hooks are not yet customized by the theme or a plugin.
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
$tabs['delivery_information'] = array(
'title' => __( 'Additional information', 'woocommerce' ),
'priority' => 16,
'callback' => 'product_additional_info_tab'
);
return $tabs;
}
function product_additional_info_tab() {
$info = get_post_meta(get_the_ID(),
'additional_product_tabs_metabox_content', true);
echo $info;
}
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.
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 have 19 items in the "xyz" category currently but I am only able to see 5 of them at a time and shows pagination I don't want pagination.
Is there a way to make it to where more than 5 items show up on your first page of your xyz category ?
i added following code to my function.php of template
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 10;' ), 19 );
but still its displaying 5 products .
as of php 7.2 create_function is depricated.
following filter is available to change the amount of products in the archive pages (i would only suggest to use that one, if it is different from your wordpress setting under settings>reading)
/**
* WC: change products per page
* #return int
*/
function so22835795_loop_shop_per_page() {
return -1; //return any number, -1 === show all
};
add_filter('loop_shop_per_page', 'so22835795_loop_shop_per_page', 10, 0);
The loop_shop_per_page filter did not work for me as the theme was overriding it. So I used the woocommerce_product_query filter as follows:
<?php
add_action( 'woocommerce_product_query', 'so22835795_woocommerce_products_per_page', 1, 50 );
function so22835795_woocommerce_products_per_page( $query ) {
if ( $query->is_main_query() ) {
$query->set( 'posts_per_page', '5' );
}
}
This can be changed in the Reading Settings section of the Settings tab on the dashboard.
The option Blog pages show at most controls how many products can be seen. Changing that to 19 will allow all 19 products to be shown.
EDIT
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 19;' ), 20 );
ANOTHER EDIT:
In the woocommerce/includes/class-wc-query.php page there is the following on line ~365
$q->set( 'posts_per_page', $q->get( 'posts_per_page' ) ? $q->get( 'posts_per_page' ) : apply_filters( 'loop_shop_per_page', get_option( 'posts_per_page' ) ) );
Change it to:
$q->set( 'posts_per_page', $q->get( 'posts_per_page' ) ? $q->get( 'posts_per_page' ) : apply_filters( 'loop_shop_per_page', '19') );
add this code to our theme's function.php file
add_filter('loop_shop_per_page', create_function('$cols', 'return 19;'));
it is working for me.
Thakns