• Resolved lilmofo

    (@lilmofo)


    First, thanks for this plugin. Good work.
    I have a minor issue with the Pro Version:
    When we create new orders the shipping cost is displayed and calculated correctly. We then “Go to checkout” in order to finish the payment according to the customers needs. Until here everything seems to be correct: the shipping cost is calculated correctly based on the billing address.

    Now, when we take a look at the order in WooCommerce there is a difference to regular orders: the shipping line item is missing (usually displayed below the line items with a truck icon). So in effect it’s also missing from the totals listed in all order emails, and furthermore not listed on the PDF.

    That said, it would be nice to have this fixed in the plugin itself.
    We are using WooCommerce 3.6.2, WP 5.2, Germanized Pro and Flatsome Theme.
    I more or less fixed this today by hooking a function into WooCommerce hooks, checking if there is such a shipping line item present or not, and if necessary appending it for all physical goods carts. I noticed that the method for getting the shipping cost did give me the correct amount, still the line item wasn’t there.

    Weirdly, when simply saving the new order instead of going to the checkout I see a shop_order with status draft that does have the shipping cost line item.

    Thanks

    • This topic was modified 4 years, 11 months ago by lilmofo.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello

    have you updated the plugin to recent version (released on May 21st)?

    If you still have same problem – please, submit ticket to helpdesk.

    thanks, Alex

    Thread Starter lilmofo

    (@lilmofo)

    Yes, I double checked and we use v3.3.0
    For the time being I did the fix in post order creation hooks which isn’t optimal, but I had trouble modifying the WC()->cart->___ contents, and saving the session.

    
    function phone_orders_fix($order){
        
        if ($order instanceof WC_Order) {
            // all good
        } else {
            $order = wc_get_order($order);
        }
        
        $has_shipping = false;
        $is_virtual = true;
    
        $shipping_total = $order->get_shipping_total(); // seems ok
        $order_id = $order->get_id();
            
        // check in fees
        foreach( $order->get_items('fee') as $item_id => $item_fee ){
            if ($item_fee->get_name() === getenv('SHIPPING_TITLE')) {
                $has_shipping = true;
            }
        }
        
        // check in shipping
        foreach( $order->get_items('shipping') as $item_id => $item_fee ){
            if ($item_fee->get_product() === getenv('SHIPPING_TITLE')) {
                $has_shipping = true;
            }
        }
        
        // assume only downloads until a physical good is found
        foreach( $order->get_items() as $item_id => $item ){
            /* @var WC_Product $product */
            $product = $item->get_product();
            if (!$product->is_downloadable()) {
                $is_virtual = false;
            }
        }
        
        /**
         * If this order has no shipping line item AND has physical goods... we need to add a shipping line item manually
         */
        if ( !$has_shipping && !$is_virtual) {
            // so...  
            // we have an order with shipping cost but theres no line item
            error_log('so... we have an order with shipping cost but theres no line item');
            $country_code = $order->get_shipping_country();
            
            // Set the array for tax calculations
            $calculate_tax_for = [
                'country' => $country_code,
            ];
            
            // Optionally, set a total shipping amount
            switch($country_code) {
                case 'DE':
                    $new_ship_price = getenv('SHIPPING_COST_DE_NET');
                    break;
                case 'AT':
                case 'CH':
                    $new_ship_price = getenv('SHIPPING_COST_AT_CH_NET');
                    break;
                default:
                    $new_ship_price = getenv('SHIPPING_COST_REST_NET');
                    break;
            }
            
            // Get a new instance of the WC_Order_Item_Shipping Object
            $item = new WC_Order_Item_Shipping();
            
            $item->set_method_title( getenv('SHIPPING_TITLE') );
            $item->set_method_id( "flat_rate:1" ); // set an existing Shipping method rate ID
            $item->set_total( $new_ship_price ); // (optional)
            $item->calculate_taxes($calculate_tax_for);
            
            $order->add_item( $item );
            
            $order->calculate_totals();
            $order->save();
        }
    }
    
    add_action( 'woocommerce_order_status_pending', 'phone_orders_fix',  9999, 1 ); // upon payment creation
    add_action( 'woocommerce_order_status_pending_to_on-hold_notification', 'phone_orders_fix',  9999, 1 );
    
    • This reply was modified 4 years, 11 months ago by lilmofo.
    Plugin Author algol.plus

    (@algolplus)

    hi

    But last version 3.3.1 😉

    Please, continue discussion via helpdesk. This issue is not related to free version.
    thanks, Alex

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Missing shipping line item’ is closed to new replies.