Woocommerce product bundles doubling - wordpress

I have installed the Woocommerce product bundles plugin where I am having issues. For example:
My bundle is setup like:
When you buy Product-A, You can optionally buy Product-B and Product-C in that bundle.
When I purchase 4x Product-A and optionally add 2x Product-B and click add to cart my cart contents/total is
4x Product-A
8x Product-B
It seems as though however many of the parent product there is it will times itself by optional products qty.
Hope someone can help.

Fixed this problem.
I looked at wc-pb-cart.php and looked over the function bundle_add_to_cart and came across this:
$quantity = $bundled_item->is_sold_individually() ? 1 : $item_quantity * $bundled_item->get_quantity();
So I created my own class and included it within functions.php and then extended WC_PB_Cart and called my new function(same function just removed * $bundled_item->get_quantity() which was causing the duplication.
Then I needed to remove_action on bundle_add_to_cart in my functions.php
include 'class-cartFeatures.php';
remove_action( 'woocommerce_add_to_cart', array( WC_PB_Cart::instance(), 'bundle_add_to_cart' ), 10, 6 );
add_action( 'woocommerce_add_to_cart', array( new cartFeatures(), 'bundle_add_to_cart_excalibur' ), 10, 6 );

Related

Change cart total for payment gateways In WooCommerce 2.6.x [duplicate]

I am running into issues with the cart total only displaying 0
Essentially what I am trying to do is only accept a deposit total of a certain amount after all cart items have been added to the carts subtotal.
So for example if the customer adds $100 worth of items, they would only pay $10 initially or (10%) of the subtotal as the total value.
I took the code from here: Change total and tax_total Woocommerce and customize it this way:
add_action('woocommerce_cart_total', 'calculate_totals', 10, 1);
function calculate_totals($wc_price){
$new_total = ($wc_price*0.10);
return wc_price($new_total);
}
But the total amount shows 0.00 when that code is enabled. If removed the code, I get the standard total.
I also could not find on the woocommerce site where the full api is listed, only generic articles related to how to create a plugin.
Any help or a point in the right direction would be great.
This does not answer this question. Loic's does. This is another way of doing it to show a line item of 10% off:
function prefix_add_discount_line( $cart ) {
$discount = $cart->subtotal * 0.1;
$cart->add_fee( __( 'Down Payment', 'yourtext-domain' ) , -$discount );
}
add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_discount_line' );
Since Woocommerce 3.2+
it does not work anymore with the new Class WC_Cart_Totals ...
New answer: Change Cart total using Hooks in Woocommerce 3.2+
First woocommerce_cart_total hook is a filter hook, not an action hook. Also as wc_price argument in woocommerce_cart_total is the formatted price, you will not be able to increase it by 10%. That's why it returns zero.
Before Woocommerce v3.2 it works as some WC_Cart properties can be accessed directly
You should better use a custom function hooked in woocommerce_calculate_totals action hook this way:
// Tested and works for WooCommerce versions 2.6.x, 3.0.x and 3.1.x
add_action( 'woocommerce_calculate_totals', 'action_cart_calculate_totals', 10, 1 );
function action_cart_calculate_totals( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( !WC()->cart->is_empty() ):
## Displayed subtotal (+10%)
// $cart_object->subtotal *= 1.1;
## Displayed TOTAL (+10%)
// $cart_object->total *= 1.1;
## Displayed TOTAL CART CONTENT (+10%)
$cart_object->cart_contents_total *= 1.1;
endif;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Is also possible to use WC_cart add_fee() method in this hook, or use it separately like in Cristina answer.

Add the same product more than once, in an order from the admin panel

I need to be able to add the same product more than once within an order in WooCommerce.
This is the scenario.
I create an order manually from the admin panel of Woocommerce, and I need to be able to add the same product N times to this order.
Basically I need something like what this snippet does, but for the backend instead of for the frontend cart.
function separate_individual_cart_items( $cart_item_data, $product_id ) {
$unique_cart_item_key = md5( microtime() . rand() );
$cart_item_data['unique_key'] = $unique_cart_item_key;
return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'separate_individual_cart_items', 10, 2 );
Any suggestion to get this?
Thank you.
In order to duplicate product N times you can add any woocommerce clone duplicate plugin.
You can download a plugin on link to accomplish your task

Removing pagination from Woocommerce product variations

By default, from the edit product page, Woocommerce begins to paginate product variations once you have more than 20 for a single product. How can I remove this pagination, so that all product variations can be viewed at once from the edit screen, regardless of how many there are?
The previous answer is an absolute no-go. NEVER change plugin core files.
Please do the following:
add the following line in your functions.php (preferably in your child-theme folder too)
//Display 24 products on archive pages
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );
I achieved it thus (my use-case was to remove pagination entirely):
add_filter('woocommerce_admin_meta_boxes_variations_per_page', function() {
return PHP_INT_MAX;
});
https://woocommerce.wordpress.com/2015/07/13/improving-the-variations-interface-in-2-4/
The pagination restricts editing and saving to 10 variations at a time. But you can change the amount using the woocommerce_admin_meta_boxes_variations_per_page filter if needed.
So, as per: https://www.thathandsomebeardedguy.com/increase-woocommerce-variations-per-page-in-the-admin-product-screen/ edit your functions.php and paste the snippet there.
By default WC set pagination as 15 variations but you can change it from below file
/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-assets.php
line no 205
'variations_per_page' => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) )
Replace
'variations_per_page' => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 1000 ) )

Woocommerce removes shipping labels from cart and checkout

I am selling services using Woocommerce and have enabled shipping address on checkout using snippet, which works fine.
In order to avoid error on checkout, I have to enable free shipping. I do not want the label Shipping: Free Shipping to be shown on Cart and Checkout. Tried using the following snippet, but it didn't work. Please help.
add_filter( 'woocommerce_cart_shipping_method_full_label', 'remove_shipping_label', 10, 2 );
function remove_shipping_label( $label, $method ) {
$new_label = preg_replace( '/^.+:/', '', $label );
return $new_label;
}
You can disable shipping in the woocommerce settings.
To force clients to fill in their adress to ship your products to, copy and paste the following code in to your functions.php file
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true', 50 );
So basically your free shipping label goes away because you disabled shipping and the costs etc but clients still need to fill in the address fields.
Hope this helps!

woocommerce custom price based on quantity

$productPrice = $12.00
Is it possible if productQuantity = 12 would be $productPrice = $99.00
I have used these 2 filters and also i have used dynamic pricing plugin that also not worked
add_action( 'woocommerce_before_calculate_totals', 'cp_add_custom_price' );
add_action('woocommerce_before_cart_table', 'discount_10');
Please let me know this thing is possible
Thanks
I can make it work with this hook
add_action( 'woocommerce_before_calculate_totals', 'cp_add_custom_price' );
you can do as much customization you need want to custom price based on quantity with the above hook
$value['data']->price = $customPrice;
based on my requirement I have calculated $customPrice while adding 12 product in cart.

Resources