• Resolved intolap

    (@intolap)


    Hi Great Support,

    I am trying to achieve a situation –

    I am setting a custom pricing and a fee in the cart on checkout page based on the country. But when I place the order it records the original price of the product and not the custom product price.

    Can help in this please?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @intolap

    Thanks for reaching out!

    I understand that you are setting up a custom price plus an additional fee on your site’s cart and checkout pages, however, it is not working as expected, correct?

    As a first step, can you please share with us how are you adding the custom price and fee to your site as this is not part of the core functions of WooCommerce?

    If this was added thru a third-party plugin or a custom code, it would be best to reach out to the developers for further assistance here.

    Thanks!

    Thread Starter intolap

    (@intolap)

    /* Custom codes by INTOLAP */
    
    add_action('woocommerce_checkout_update_order_review', 'armd_update_order_review');
    
    function armd_update_order_review( $posted_data ) {
    
        // Parsing posted data on checkout
    
        $post = array();
    
        $vars = explode('&', $posted_data);
    
        foreach ($vars as $k => $value){
    
            $v = explode('=', urldecode($value));
    
            $post[$v[0]] = $v[1];
    
        }
    
        $billing_country = $post['billing_country'];
    
        if ($billing_country == "ZA") {
    
            $tax = 0; $sub_total = 0;
    
            foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    
                $product = $cart_item['data'];
    
                $price = $cart_item['data']->get_price();
    
                $percentage = 15;
    
                $new_price = ($price*100)/(100+$percentage);
    
                $sub_total += $new_price;
    
                $tax += ($price - $new_price)*$cart_item['quantity'];
    
                $cart_item['data']->set_price( floatval($new_price) );
    
            }
    
            WC()->session->set( 'tax' , $tax );
    
            WC()->session->set( 'sub_total' , $sub_total );
    
        }else{
    
            WC()->session->__unset( 'tax' );
    
            WC()->session->__unset( 'sub_total' );
    
        }
    
    }
    
    add_action('woocommerce_cart_calculate_fees','armd_wc_custom_fee');
    
    function armd_wc_custom_fee() {
    
        if(!is_checkout())return false;
    
        $billing_country = WC()->customer->get_billing_country();
    
        $tax = WC()->session->get( 'tax' );
    
        if($billing_country == 'ZA' && !empty($tax)){
    
            WC()->cart->add_fee('VAT @ 15%:', $tax);
    
        }
    
    }
    
    We are using woocommerce hooks to achieve this till the display of custom price and the fee on checkout page. But the time I press Place Order button on Checkout page, it creates the order with the original product price and not the custom price.
    
    
    Saif

    (@babylon1999)

    Hello @intolap,

    I understand you want to add a surcharge based on the customer’s country.

    You can actually achieve this with fewer lines with the following snippet: https://woocommerce.com/document/add-a-surcharge-to-cart-and-checkout-uses-fees-api/#section-3


    Just add the list of countries in the $county array. :‎)

    Hope this helps!

    Thread Starter intolap

    (@intolap)

    I am sorry but my problem is not about reflecting the custom fee in the order. It is working.

    What is not reflecting is the custom product price. Kindly check the codes that I pasted to understand better.

    We have a situation where a product is priced as 1500

    Condition A: If user is from ZA, then the price should be X + 15% of X = 1500

    Condition B: If not ZA, then it should be just 1500

    In “A” the price f the product is also customized in cart and the same is displayed on checkout page as well. But the same price is not carried to the order. The order shows 1500 as the line total which is wrong because we have set custom price for the product.

    Hope this time I am clear with my lookout.

    Saif

    (@babylon1999)

    So if I understand this correctly, you want the product price only to be increased.

    Sorry to disappoint, but customizations are not within our scope of support, I suggest you hire a WooExpert if you need further assistance in debugging your code.

    If you’re comfortable with a plugin solution, you can check the Price By Country extension.

    All extensions sold on WooCommerce.com have a 30-day refund policy and premium email support. If the product doesn’t work the way you need it or you think another product would work better, we are more than happy to provide a full refund.

    Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom product pricing and fee not reflecting in order’ is closed to new replies.