Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello

    Were you able to add this field to export ?

    just in case, we have code for this plugin
    https://algolplus.com/plugins/snippets-plugins/#local_pickup_plus

    thanks, Alex

    Thread Starter virap

    (@virap)

    Yes I added the code.

    But I still don’t see how to sort the export by pickup dates

    Plugin Author algol.plus

    (@algolplus)

    Hello

    Please, check this section
    https://algolplus.com/plugins/code-samples/#sort_by_products

    Adapt code, to use pickup date instead of product name.
    thanks, Alex

    Thread Starter virap

    (@virap)

    How? Please post or direct me to a URL that shows steps to take and code to use.

    It is beyond me to guess what needs to be edited and how in that code.

    Thank you.

    Plugin Author algol.plus

    (@algolplus)

    What format do you use ?

    Thread Starter virap

    (@virap)

    The format is CSV

    Thank you.

    Plugin Author algol.plus

    (@algolplus)

    I create code for CSV format , but you must replace

    return $a['plain_products_name'] < $b['plain_products_name'] ? -1: 1;

    with

    return $a['_pickup_date'] < $b['_pickup_date'] ? -1: 1;

    Here is unmodified code

    // Sort by product name
    // Format CSV
    // option "Fill order columns for" = ALL rows
    class Woe_Sort_By_Product_Name_CSV {
    	var $session_key = "woe_temp_rows_csv";
    	function __construct() {
    		//add settings
    		add_action("woe_settings_above_buttons", array($this,"draw_options") );
    		
    		// start SESSION
    		add_filter("woe_settings_validate_defaults", function($settings) {
    			if( !empty($settings[ 'sort_by_products' ]) ) {
    				@session_start();
    				
    				//stop default output for rows
    				add_action("woe_csv_header_filter",array($this,"init_session_data"),10,2);
    				add_action("woe_csv_output_filter",array($this,"record_csv_rows"),10,2);
    				add_action("woe_csv_print_footer",array($this,"sort_rows"),10,2);
    			}	
    			return $settings;
    		});
    		
    	}
    
    	// 1
    	function draw_options($settings){
    		$selected = !empty($settings[ 'sort_by_products' ]) ? 'checked': '';
    		echo '<input type=hidden name="settings[sort_by_products]" value="0">
    		<input type=checkbox name="settings[sort_by_products]" value="1" '. $selected .'>
    		<span class="wc-oe-header">Sort by products,  Format CSV</span>';
    	}
    		
    	// 2 init storage
    	function init_session_data($data) {
    		$_SESSION[$this->session_key] = array();
    		return $data;
    	}
    
    	//3 down't export rows 
    	function record_csv_rows($data,$obj) {
    		$_SESSION[$this->session_key][] = $data;
    		return false;
    	}
    	//4 sort and print 
    	function sort_rows($handle,$formatter) {
    		usort($_SESSION[$this->session_key], function($a,$b) {
    			return $a['plain_products_name'] < $b['plain_products_name'] ? -1: 1; 
    		}); 
    		foreach($_SESSION[$this->session_key] as $pos=>$data)
    			fputcsv($handle,$data, $formatter->delimiter, $formatter->enclosure);
    	}
    }
    new Woe_Sort_By_Product_Name_CSV();
    Thread Starter virap

    (@virap)

    Perfect! I think it works as expected. Many thanks.

    Plugin Author algol.plus

    (@algolplus)

    you’re welcome

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Sorby by Local Pickup time’ is closed to new replies.