I wonder if it's possible to programmatically add all cross-sell products as upsells too (or the other way around)? The reason I want to do this is that I want to show the same products as both cross-sells and upsells without having to add them manually twice.
Just found a way for how to replace a product's upsells with the cross-sells instead:
add_filter( 'woocommerce_product_get_upsell_ids', 'custom_upsell_ids', 20, 2 );
function custom_upsell_ids( $upsell_ids, $product ) {
return $product->get_cross_sell_ids();
}
Related
i want change update item in woocomerce. I use plugin (sumo measures) to calculate metadata (size, pack) and when I try to update quantity of cart product metadata dont change.
My idea to solution problem is remove item from cart and add.
My code:
add_action( 'woocommerce_update_cart_action_cart_updated', 'on_action_cart_updated', 20, 1 );
function on_action_cart_updated( $cart_updated ){
WC()->cart->empty_cart();
foreach( WC()->cart->get_cart() as $cart_updated ){
$product_id = $cart_updated['product_id'];
WC()->cart->add_to_cart( $product_id, $cart_updated['quantity'] );
}
}
But code dont work.
I find using this action hook : woocommerce_update_cart_action_cart_updated
Using this you can get the cart data: $cart = WC()->cart->cart_contents;
You can get the cart itemmeta and quantity and then update the Sumo measures cart item data.
Because to remove and re-add the product with updated quantity will be the length process and also there will be much other factors need to take care.
Please let me know if you find any issues.
Thanks.
I'm using WooCommerce and Elementor Pro. Is there any way to add specific product attributes (e.g. gross and net weight) below the Add to cart button?
It seems like an obvious thing but I haven't found options or snippets for it.
First you add attributes to product. Then you use this snippet in functions.php:
// maybe remove tab with attributes
add_filter( 'woocommerce_product_tabs', 'remove_info', 100, 1 );
function remove_info( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
// show attributes
add_action( 'woocommerce_single_product_summary', 'summary_attributes', 35 );
function summary_attributes() {
global $product;
if ( $product->has_attributes() ) {
wc_display_product_attributes( $product );
}
}
Setting Up WooCommerce Attributes
go to Products > Attributes
Add the attribute name
Slug will automatically be created, and we can leave the rest of these options untouched.
Click “Add attribute” button and your attribute will be added.
Configure The Attributes
After creating attribute, now we can add different variation on your product. Click on the Configure Terms option.
Enter the variation
Add some short description
Click on the add new tab
To understand it in a better way you can follow this tutorial
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
Basically, I finished building custom plugin for my client.
the only thing after products added to cart, before the checkout.
user able to change the quantity of the products, is it possible to display the selected quantity, but disabled the options to read only so client will able to see the quantity in cart page that he selected but can't change it?
and to apply this only to products that I used with my plugin either product ids or better category id because all the products there.
other product display and able to change quantity regular
by the way its regular products not virtual and not Sold Individually i need to find a way to limit clients to change quantity for some products only in cart page!, and not in product page.
I really appreciate any help.
As mentioned in the comment, you can use the woocommerce_cart_item_quantity filter for that. So that might look something like this:
function 668763_change_quantity_input( $product_quantity, $cart_item_key, $cart_item ) {
$product_id = $cart_item['product_id'];
// whatever logic you want to determine whether or not to alter the input
if ( $your_condition ) {
return '<h3>' . $item['quantity'] . '</h3>';
}
return $product_quantity;
}
add_filter( 'woocommerce_cart_item_quantity', '668763_change_quantity_input', 10, 3);
This would be just a simple example to replace the input with a h3 element containing the quantity. It can easily be adjust to alter the quantity input element to your liking.
i am new to woocommerce, actually i want to customize product display so i manually parse products from database i want to remove an item from woocommerce cart through product id, i have found this function,
$woocommerce->cart->get_remove_url($cart_item_key); in core woocommerce cart class, but i am unable to understand what i have to write in $cart_item_key, i have tried to product id or product url in it but its not removing product item from cart, can somebody help me please what i have write in this variable $cart_item_key,
/* Gets the url to remove an item from the cart.
*
* #return string url to page
*/
its description of that function, i have tried using full url of product page and also slug
Regards
Arsalan
I know its an old post but it may help someone.
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
if($cart_item['product_id'] == $your_product_id)
$woocommerce->cart->get_remove_url($cart_item_key);
}
Hope its helps..