My products price is based on USD , but i want change USD to IRR with a Conversion Rate (1 USD = 3500 IRR) in shop and checkout . I found this code but it works only for product veiw and when i click on cart or checkout price change to USD .
add_filter( 'woocommerce_get_price_html', 'wpa83367_price_html', 100, 2 );
function wpa83367_price_html( $price, $product ){
$price = get_post_meta( get_the_ID(), '_regular_price', true);
$toman = 3500;
$total = $price * $toman . ' ' . 'تومان';
return $total;
}
Related
So, I have a woocommerce shop where a 10% discount is applied to all products in the cart and at checkout if a certain payment gateway is used.
My shop has both simple and variable products, and they are all virtual products. I thought of showing on the product page the following information:
the lowest price (for variable products)
the 10% discounted price I could get at checkout.
To do this I used the following code for variable products:
add_filter( 'woocommerce_variable_sale_price_html', 'wpglorify_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wpglorify_variation_price_format', 10, 2 );
function wpglorify_variation_price_format( $price, $product ) {
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( 'A partire da: %1$s (' . $prices[0]*.9 . '€ se paghi online)' , 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'A partire da: %1$s (' . $prices[0]*.9 . '€ se paghi online)' , 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
return $price;
}
For simple products I used this snippet instead:
add_filter( 'woocommerce_get_price_html', 'change_displayed_price_html', 10, 2 );
function change_displayed_price_html( $price, $product ) {
if( $product->is_type('simple') ){
$regular_price = (float) $product->get_regular_price();
$saving_price = $regular_price*.9;
$price .= sprintf( __(' (€%s se paghi online)', 'woocommerce' ), $saving_price );
}
return $price;
}
Everything works fine, but on variable products I have a problem. When I select a variation, I would like to give the same information next to the price being shown and related to that variation. I tried with the following snippet:
add_filter('woocommerce_available_variation', 'variation_custom_text', 10, 3 );
function variation_custom_text( $price, $product, $variation ) {
$variation_price = (float) $product->get_variation_price();
$saving_price = $variation_price*.9;
$price['availability_html'] .= sprintf( __(' (€%s se paghi online)', 'woocommerce' ), $saving_price );
return $price;
}
The problem is that the discounted price is calculated on the price of the first variation, regardless of which variation I select. For example, if variation A = $100, a discounted price of $90 is shown. If I select variation B = $120, a discounted price of $90 is always shown. Where am I doing wrong?
Thanks for your answers.
I need to set up shipping price like this:
1 - 5 qty for $60
6 - 10 qty for $90
How can I do this? So if someone buys 3 pieces from the product then is charged 60 for shipping, if 6 or more then 90.
The basic [qty] placeholder woocommerce provides can't do this and did not find any plugin that can do it.
Maybe something like this ? Add following function in your active theme functions.php file
add_filter( 'woocommerce_package_rates', 'custom_shipping_costs', 20, 2 );
function custom_shipping_costs( $rates, $package ) {
global $woocommerce;
$qty = $woocommerce->cart->cart_contents_count;
//error_log($qty);
foreach( $rates as $rate_key => $rate ){
// Excluding free shipping methods
if( $rate->method_id != 'free_shipping'){
// Between 1 and 5
if($qty > 0 && $qty <= 5):
$rates[$rate_key]->cost = '60';
// Between 6 and 10
elseif($qty > 5 && $qty <= 10):
$rates[$rate_key]->cost = '90';
else:
// For over 10
$rates[$rate_key]->cost = '60';
endif;
}
}
return $rates;
}
I have this code to display the price.
function edit_selected_variation_price( $data, $product, $variation ) {
$price = $variation->price;
$price_incl_tax = $price + round($price * ( 23 / 100 ), 2);
$price_incl_tax = number_format($price_incl_tax, 2, ",", ".");
$price = number_format($price, 2, ",", ".");
$display_price = '<div><span class="price">';
$display_price .= '<span>Cena netto</span><span class="amount">' . $price .'<small class="woocommerce-price-suffix"> zł</small></span>';
$display_price .= '</div><div>';
$display_price .= '<span>Cena brutto</span><span class="amount">' . $price_incl_tax .'<small class="woocommerce-price-suffix"> zł</small></span>';
$display_price .= '</span></div>';
$data['price_html'] = $display_price;
return $data;
}
add_filter( 'woocommerce_available_variation', 'edit_selected_variation_price', 10, 3);
How to get the maximum price displayed without choosing any variants?
I do not fully understand your question, you want the max price from what prices (incl tax and ...)?
However, when you have different prices in an array (or as loose variables), consider using the PHP max() function:
https://www.php.net/manual/en/function.max.php
That will return the highest value (Hope that's what you're after)
I'd like to use Woocommerce over WordPress for my shop, but clients should be able to buy the product by either unit or weight.
If X units were bought, we must measure the actual weight of the purchase (obtained during the picking and packing of the order), and adjust the price accordingly.
Is there an easy way to do this on Woocommerce?
Thanks
You can do your modification using follows code snippet -
function adjust_price_based_on_weight( $cart_object ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = $cart_item['data'];
$product_id = $cart_item['product_id'];
$quantity = $cart_item['quantity'];
$product_price = floatval( $_product->get_price() ); // Actual product price
// Do your calculation based on product quantity and weight
// for example suppose product per unit weight 2 kgs and add to cart number of unit is 3.
$product_unit_weights = $quantity * 2; // where 2kg/per unit and $quantity is 3
if( $product_unit_weights > 5 ) { // if units weights is greter than 5 kgs additional cost 10.
$additionalPrice = 10;
$_product->set_price( $product_price + $additionalPrice );
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'adjust_price_based_on_weight', 99 );
ETH 5 ($ 3.753,65)
I want to show two currencies in checkout Subtotal & Totals in woocommerce. I'm guessing i'm using the wrong hook?
Example Image
// Convert to USD
function convert_price_cart( $price ){
$convertion_rate = 780.730022;
$new_price = $price * $convertion_rate;
return number_format($new_price, 2, '.', '');
}
add_filter( 'wc_price', 'my_custom_price_format', 10, 3 );
function my_custom_price_format( $formatted_price, $price, $args ) {
// The currency conversion custom calculation function
$price_usd = convert_price_cart($price);
// the currency symbol for US dollars
$currency = 'USD';
$currency_symbol = get_woocommerce_currency_symbol( $currency );
$price_usd = $currency_symbol.$price_usd; // adding currency symbol
// The USD formatted price
$formatted_price_usd = "<span class='price-usd'> ($price_usd)</span>";
// Return both formatted currencies
return $formatted_price . $formatted_price_usd;
}
Is there anybody could help me with this situation.