• Resolved GTech Web Store

    (@gtechwebstore)


    Hi there:
    I’ve got 2 issues on my site when trying to use this plugin

    1.say by default site shows AUD, add any product to cart, say https://stage.gtechwebstore.com/product/baseus-suyl-g01-mini-gravity-car-air-vent-mount-holder-for-4-6-5-inch-smart-phones/ AUD 12.38
    2. view cart, it shows $12.38 in total
    3. change quantity to 2, update cart, it shows total $24.26 as I’ve got a logic in woocommerce_before_calculate_totals to give 2% discount based on quantity = 2
    4. change to USD, cart shows original price $8.35 is correct, but discount price is 5.52 seems wrong, looks like exchange rate applied twice
    5. looking shipping area below, the shipping rate $5 and $20 are not converted to USD, those rate are calculated in filter woocommerce_package_rates

    Thanks in advance

    Gary

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Dmytro Holovnia

    (@dholovnia)

    Hi Gary,

    Step #3 need more info. Please provide the code you are using. Most likely you are using in your code function where our plugin is hooked in. So we are getting 2 runs instead of 1.

    Try for test to remove your code with discount and check with USD again.

    Regards,
    Dima

    Thread Starter GTech Web Store

    (@gtechwebstore)

    Hi, Dima:

    Thanks for the response, the code below are used for recalculating the total based on quantity discount, will try disable that piece later

    function gtechwebstore_before_calculate_totals($cart) {
    //get max vip discount
    $user = wp_get_current_user();
    //get _force_reassign_role_time meta, reassign role if required
    $date = get_user_meta($user->ID, ‘_force_reassign_role_time’, true );
    if ($date === false || time() > strtotime($date)) {
    gtechwebstore_assign_role_based_on_completed_order($user);
    }

    $vip_discount = 1;
    $roles = (array) $user->roles;
    if ( in_array( ‘vip2’, $roles ) ) $vip_discount = 0.98;
    if ( in_array( ‘vip4’, $roles ) ) $vip_discount = 0.96;
    if ( in_array( ‘vip6’, $roles ) ) $vip_discount = 0.94;
    if ( in_array( ‘vip8’, $roles ) ) $vip_discount = 0.92;
    if ( in_array( ‘vip10’, $roles ) ) $vip_discount = 0.9;

    //registered user, first order ever? 10% off then
    if ($user->exists() && count(wc_get_orders( array(
    ‘meta_key’ => ‘_customer_user’,
    ‘meta_value’ => $user->ID,
    ‘status’ => array(‘wc-pending’, ‘wc-processing’, ‘wc-on-hold’, ‘wc-completed’),
    ‘limit’ => 1,
    ‘return’ => ‘ids’,
    ) )) == 0) {
    $vip_discount = 0.9;
    }

    $product_quantities = array();

    foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
    //gift price = 0
    if (array_key_exists(“is_gift”, $cart_item) && $cart_item[“is_gift”])
    $cart_item[“data”]->set_price(0);
    else {
    //get total quantity for same product
    $product_id = $cart_item[“product_id”];
    $quantity = $cart_item[“quantity”];
    if (array_key_exists($product_id, $product_quantities))
    $product_quantities[$product_id] += $quantity;
    else $product_quantities[$product_id] = $quantity;
    }
    }
    //discount
    foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
    $product = $cart_item[“data”];
    if (array_key_exists(“is_gift”, $cart_item) && $cart_item[“is_gift”]) {
    ;
    }
    else if (array_key_exists(“price”, $product->get_changes())) {
    ;
    } else {
    $quantity = $product_quantities[$cart_item[“product_id”]];
    $quantity_discount = 1;
    if ($quantity > 1) { $quantity_discount = 0.98; }
    if ($quantity > 2) { $quantity_discount = 0.96; }
    if ($quantity > 3) { $quantity_discount = 0.94; }
    if ($quantity > 4) { $quantity_discount = 0.92; }
    if ($quantity > 5) { $quantity_discount = 0.9; }
    $product->set_price($product->get_price() * min($vip_discount, $quantity_discount));

    }
    }

    }
    add_action( ‘woocommerce_before_calculate_totals’, ‘gtechwebstore_before_calculate_totals’, 20, 1 );

    Plugin Author RazyRx

    (@razyrx)

    Hello @gtechwebstore,

    You have get_price function without context. By default context is view.
    We are apply changes on view context, but in you case it happenes twice.
    Use for example get_price('discount'); to prevent it.

    Regards,
    Oleg

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘2 Currency Conversion issues’ is closed to new replies.