• Resolved Mick

    (@mickert)


    I have a function called wc_csv_export_modify_row_data inside of functions.php. Within this function I check what the chosen shipping method was. I used this code:

    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping = $chosen_methods[0];
    
    if ($chosen_shipping == 'local_delivery') {
      // do something
    } else {
      // do something else
    }

    Unfortunately, maybe with the update to version 2.5, this doesn’t work anymore. The following error message appears:

    Fatal error: Call to a member function get() on a non-object in path/functions.php on line 743

    https://www.ads-software.com/plugins/woocommerce/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    When does this code run? Maybe it’s too early. It should also only be ran on the frontend, never in admin.

    Thread Starter Mick

    (@mickert)

    This code will run when its being exported as an csv.

    function wc_csv_export_modify_row_data( $order_data, $order, $csv_generator ) {}
    add_filter( 'wc_customer_order_csv_export_order_row', 'wc_csv_export_modify_row_data', 10, 3 );

    Depending on the chosen shipping method some options will change inside the csv.

    Plugin Contributor Mike Jolley

    (@mikejolley)

    But thats in admin right? Where does export take place?

    Thread Starter Mick

    (@mickert)

    The export will take place on two different places.

    1: on the order place (/wp-admin/edit.php?post_type=shop_order). Here it is possible to select an order and export it as an csv

    2: there is also a plugin running named ‘WooCommerce Customer/Order CSV Export’ which exports the csv file to a webserver

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Right- then this code is wrong. It’s for frontend (cart) selected shipping. If you’re in admin, this is not relevant.

    Thread Starter Mick

    (@mickert)

    The code worked before. How can I change it so it will work?
    I need to know what the chosen shipping method is.

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Sounds like you want the chosen method for the order being exported, NOT the chosen method in the cart for the logged in user. This code **never** worked in that case ??

    I don’t have the code you’ll need because I’d need to look at the exporter code, so I think you’ll need a developer to look into it for you. jobs.wordpress.net

    Thread Starter Mick

    (@mickert)

    Why do you need the exporter code? It’s just basic Woocommerce code.
    But in other words, I have found a solution:

    Give the parameter $order_data to the function. Inside $order_data you find the shipping method.

    function wc_csv_export_modify_row_data( $order_data, $order, $csv_generator ) {
    	// check shipping method
    	$chosen_shipping = $order_data[0]['shipping_method'];
    }
    Plugin Contributor Mike Jolley

    (@mikejolley)

    Because without context I don’t know what values/variables are present. Not psychic. Glad you found a solution.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Session chosen shipping methods not working’ is closed to new replies.