I am using woocommerce plugin version 2.2.8 for my eCommerce site. Product prices in my site looks like (Rs 880.64/-). I need to round up this price to Rs 881/-.
Is there is any way to do that..?
For Eg: Product1 = Rs 880.64 (includes tax rate). It should converted to nearest decimal value.
You can try this on your theme functions.php without altering your data :
add_filter( 'woocommerce_get_price_excluding_tax', 'round_price_product', 10, 1 );
add_filter( 'woocommerce_get_price_including_tax', 'round_price_product', 10, 1 );
add_filter( 'woocommerce_tax_round', 'round_price_product', 10, 1);
add_filter( 'woocommerce_get_price', 'round_price_product', 10, 1);
function round_price_product( $price ){
// Return rounded price
return ceil( $price );
}
Related
I'd like to add a filter to Woocommerce product export to add columns but I'd like to add 5 columns using the same hook.
Is it possible to pass the hook name into the filter to allow me to determine which column the data is returned to?
For example, I want to run the following to populate 5 columns using same function (add_export_data) but the returned value would have to be determined by the hook name (containing the col number).
add_filter( 'woocommerce_product_export_product_column_val1', 'add_export_data', 10, 2 );
add_filter( 'woocommerce_product_export_product_column_val2', 'add_export_data', 10, 2 );
add_filter( 'woocommerce_product_export_product_column_val3', 'add_export_data', 10, 2 );
add_filter( 'woocommerce_product_export_product_column_val4', 'add_export_data', 10, 2 );
add_filter( 'woocommerce_product_export_product_column_val5', 'add_export_data', 10, 2 );
So ideally the function would be able to determine the hook name and then choose the relevant data to return as the value.
Thanks
From the 3rd argument, you can get the column ID then you can return the value conditionally.
Here is an example code.
/**
* Return custom columns data.
*
* #param string $value Column value.
* #param WC_Product $product Product object.
* #param string $column_id Column ID.
*
* #return string
*/
function add_export_data( $value, $product, $column_id ) {
switch ( $column_id ) {
case 'val1':
// Get the value from meta or any other way you want.
$value = $product->get_meta( 'product_custom_text', true, 'edit' );
break;
case 'val2':
// Get the value from meta or any other way you want.
$value = $product->get_meta( 'product_custom_text', true, 'edit' );
break;
default:
break;
}
return $value;
}
add_filter( 'woocommerce_product_export_product_column_val1', 'add_export_data', 10, 3 );
add_filter( 'woocommerce_product_export_product_column_val2', 'add_export_data', 10, 3 );
add_filter( 'woocommerce_product_export_product_column_val3', 'add_export_data', 10, 3 );
add_filter( 'woocommerce_product_export_product_column_val4', 'add_export_data', 10, 3 );
add_filter( 'woocommerce_product_export_product_column_val5', 'add_export_data', 10, 3 );
I used below code as mentioned in the answer of other questions but it didn't work. Just wish to do the normal rounding and remove the decimal part in final Total cart value(amount plus tax plus shipping value) displayed at checkout page AND the Total amount shown at Invoice generated by Invoice plugin. Variations are used in the product.
add_filter( 'woocommerce_get_price_excluding_tax', 'round_price', 10, 1 );
add_filter( 'woocommerce_get_price_including_tax', 'round_price', 10, 1 );
add_filter( 'woocommerce_tax_round', 'round_price', 10, 1);
add_filter( 'woocommerce_get_price', 'round_price', 10, 1);
function round_price( $price ){
// Return rounded price
return round( $price );
}
I found following function to round up the price in WordPress:
add_filter( 'woocommerce_get_price_excluding_tax', 'round_price_product', 10, 1 );
add_filter( 'woocommerce_get_price_including_tax', 'round_price_product', 10, 1 );
add_filter( 'woocommerce_tax_round', 'round_price_product', 10, 1);
add_filter( 'woocommerce_get_price', 'round_price_product', 10, 1);
function round_price_product( $price ){
// Return rounded price
return ceil( $price );
}
I have following two issues:
The overall total in the cart is not displaying the rounded prices.
The above mentioned code applies not for products with variations.
Looking forward to your help! Thanks.
Regards
I want to add additional cost in the cart product total price, not in product price nor the whole cart total price. I am referring about the product total price.
Right now i have not not try and I don't have any code.
add_action( 'woocommerce_before_calculate_totals', 'function add_additional_price' );
function add_additional_price( $cart_object ) {
$custom_price = 10; // This will be your custome price
}
You can try this
// Change the line total price
add_filter( 'woocommerce_get_discounted_price', 'calculate_discounted_price', 10, 2 );
// Display the line total price
add_filter( 'woocommerce_cart_item_subtotal', 'display_discounted_price', 10, 2 );
function calculate_discounted_price( $price, $values ) {
// You have all your data on $values;
$price += 10;
return $price;
}
// wc_price => format the price with your own currency
function display_discounted_price( $values, $item ) {
return wc_price( $item[ 'line_total' ] );
}
I don't find how to customize my pricing in my WordPress WebShop with the WooCommerce plugin.
I would like to have:
Article A 12€/kg
Article B 3€/piece
Article C 12€/colli
How is this possible please?
greets
Wim
You can add this on your functions.php
// Filter on cart price
add_filter( 'woocommerce_cart_product_price' , 'custom_price', 10, 2);
// Filter on product page
add_filter( 'woocommerce_get_price_html' , 'custom_price', 10, 2);
function custom_price( $price, WC_Product $product ){
// You can store the unit as custom fields
$unit = get_post_meta( $product->id, 'unit', true );
// Then concatenate with the price
$price .= $unit;
return $price;
}
Then you have to add a custom field on each product :