Been searhing for a simple way to add 400 g to all orders for the shipping plugin to get the correct weight. Looked at Cart total Weight and Shipping Recalculation on WooCommerce but do not need all that
You may need to change your Weight Unit first in WooCommerce > Settings > Product > Measurements section.
Then use the following filter hook in your functions.php to override the total cart weight.
add_filter('woocommerce_cart_contents_weight','add_package_weight_to_cart_contents_weight');
function add_package_weight_to_cart_contents_weight( $weight ) {
$weight = 400; // change to your expected cart content weight.
return $weight;
}
Please note that it's recommended to use a child while you add custom codes to your theme.
Related
I'm using WooCommerce Composite Products to create customer configurable packages from existing items in our Woo shop. These packages need to consist of In Stock products only, ignoring anything that is set to backorder.
For "Composite Options" I am using product categories (we have too many products to add individually), however doing it this way adds all products that are currently on backorder and set to "Allow, but notify customer".
Ideally I need a solution that allows me to use product categories which ignores any products that are set to backorder.
I tried to edit an existing snippet which would create a filter for backorder products but was not able to make any difference to the front end visible products, I'm sure more needs to be done to make it work. This is the original snippet I edited:
add_filter( 'woocommerce_composite_component_options_query_args_current', 'sw_cp_exclude_out_of_stock_options' );
function sw_cp_exclude_out_of_stock_options( $args ) {
$args[ 'exclude_out_of_stock' ] = true;
return $args;
}
I'm pretty sure the following is the basis of the code needed to figure out how to exclude back order products from component options (taken from Composite Products Plugin Editor):
woocommerce composite products > includes > data > class-wc-product-composite-data-store-cpt.php Line 1040 + 1041:
`// See 'WC_CP_Component::exclude_out_of_stock_options'.
'exclude_out_of_stock' => false`
woocommerce composite products > includes > class-wc-cp-component.php Line 785 - 789:
` /**
* Controls whether out of stock component options should be hidden.
*
* #since 8.0.3
*
* #return boolean
*/
public function exclude_out_of_stock_options() {
return apply_filters( 'woocommerce_component_options_exclude_out_of_stock', 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ), $this );
}`
Can anyone help me with the automated solution to this problem?
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
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.
Using Woocommerce plugin.
I get this code to add Tax based in the buyer rol.
It works fine but the Tax is only applied to product price. I also need to apply the same Tax to the Shipping cost.
I guess I need to use another filter parameter but I don't know which one.
Here is the real code:
function wc_re_eq( $tax_class, $product ) {
if ( is_user_logged_in() && current_user_can( 'client_re' ) ) {
$tax_class = 'R.E';
}
return $tax_class;
}
add_filter( 'woocommerce_product_tax_class', 'wc_re_eq', 1, 2 );
You should be applying that in your tax rate chart. There is a checkbox for shipping, where you apply tax to shipping.
WooCommerce documentation: https://docs.woocommerce.com/document/setting-up-taxes-in-woocommerce/#tax-rate-examples
#Jpash do you solve it?
Through the label "R.E.", I get the feeling that your problem is related to "recargo de equivalencia" of Spain.
I have the same problem. For certain users I must apply another type of tax only for the shipping costs.
Referring to this question How do I programmatically apply a coupon in Woocommerce?
I'm looking for something very similar to the final solution in the first post, but I'd like the coupon to be applied if the subtotal is > 99 euros.
How do you think I can modify the code? And since I'm a newbie... where do I have to paste the whole code?
Thanks a lot
Something like this could be done:
add_action('woocommerce_before_checkout_process','add_discount_at_checkout');
function add_discount_at_checkout(){
global $woocommerce;
$minorder = 99;
if( $woocommerce->cart->get_cart()->cart_contents_total>$minorder){
//APPLY COUPON HERE
}
}
So basically, if your cart total is greater than 99, you can do something, like add a coupon.