• Resolved mikesomersetinteractivecom

    (@mikesomersetinteractivecom)


    I have a packing list that I’m using for my Woocommerce shop that I’m pulling in some info to. The problem I’m running into is that I am unable to find the proper variable to pull in individual product prices (rather than order total) from either the cart or checkout page. Are you able to provide any feedback on this code I’ve attached to do this? It works, but I’d like to modify to get each individual price rather than order total.

    add_filter( ‘wf_pklist_package_product_table_additional_column_val’, wt_pklist_add_new_column_val’, 10, 6 );
    function wt_pklist_add_new_column_val( $column_data, $template_type, $columns_key, $_product, $item,$order )
    {
    if($template_type==’packinglist’ )
    {
    if($columns_key==’new_col’)
    {
    $order_shipping_method = is_callable(array($order, get_shipping_method’)) ? $order->get_shipping_method() : $order->order_shipping_method;
    $order_total=$order->get_shipping_method();
    if(!empty($order_total))
    {
    $column_data=$order_shipping_method;
    }
    else
    {
    $column_data=’-‘;
    }
    }
    if($columns_key==’new_col_2′)
    {
    $order_total = is_callable(array($order, get_total’)) ? $order->get_total() : $order->order_total;
    $order_total=$order->get_total();
    if(!empty($order_total))
    {
    $column_data=$order_total;
    }
    else
    {
    $column_data=’-‘;
    }

    }
    return $column_data;
    }
    }

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

    In your code, I didn’t find the scope in which you tried to access the ordered item. I guess that your problem. You have an order instance which makes it easy to get the ordered item price. You use this piece of code.

    
    $zwk_order= wc_get_order($order->ID);
    foreach ($zwk_order->get_items() as $item_id => $item_data) {
    ## Option: Including or excluding Taxes
         $inc_tax = true; 
    
         ## Option: Round at item level (or not)
         $round   = false; // Not rounded at item level ("true"  for rounding at item level)
    $total=$zwk_order->get_line_subtotal( $item, $inc_tax, $round ); // Get line subtotal - not discounted.
    }

    I hope I understand your query right and my solution will help you.

    Thank you

    Thread Starter mikesomersetinteractivecom

    (@mikesomersetinteractivecom)

    I appreciate the response, but it doesn’t work for me in this instance. The code I posted does work to pull in the total and shipping method into their own column on the packing list I use, but I’m unable to find the correct way to pull in “item amount” instead of total amount.

    What I mean specifically is, if someone orders multiple items and they show on the packing list, the column that shows Total Amount shows the same for each line item. IE: if the total order amount was $3,000 then that shows within the total column on each items line.

    I can’t find the proper way to get an item amount rather than a total amount/total order amount.

    $zwk_order= wc_get_order($order->ID);
    foreach ($zwk_order->get_items() as $item_id => $item_data) {
    ## Option: Including or excluding Taxes
    $inc_tax = true;

    ## Option: Round at item level (or not)
    $round = false; // Not rounded at item level (“true” for rounding at item level)
    $total=$zwk_order->get_line_subtotal( $item, $inc_tax, $round ); // Get line subtotal – not discounted.
    }

    Thread Starter mikesomersetinteractivecom

    (@mikesomersetinteractivecom)

    I appreciate the help from everyone, but these will not work. Specifically, my code works, but I want each item total when pulling in and not the total amount of the purchase. This code is what I am looking to modify, but it needs to stay intact in order to work with the packing slip plugin I am using.

    if($columns_key==’new_col_2′)
    {
    $order_total = is_callable(array($order, get_total’)) ? $order->get_total() : $order->order_total;
    $order_total=$order->get_total();
    if(!empty($order_total))
    {
    $column_data=$order_total;
    }
    else
    {
    $column_data=’-‘;
    }

    }
    return $column_data;
    }
    }

    Mirko P.

    (@rainfallnixfig)

    Hey @mikesomersetinteractivecom,

    We’d recommend getting in touch with the web developer community for more help on that since this forum is more focused on the default functions packaged with the WooCommerce core plugin.

    If you require assistance with custom development tasks you could reach out to some of the official WooCommerce development partners via this link below:

    https://woocommerce.com/customizations/

    Have a good day!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Packing List – Woocommerce Product prices’ is closed to new replies.