Support » Plugin: Advanced Order Export For WooCommerce » Settings are not saved

  • Resolved ementrek

    (@ementrek)


    I am trying to save settings for a custom field, customer email, total products, and the filter products by category. Even trying to uncheck and settings for any of the existing fields (order number), without custom fields, will not work.

    When I hit the save button, I get a message that says the save was successful. I do not get an errors in the console. When I go to check the list, my settings have not been applied, and the export itself does not reflect the changes either.

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

    (@algolplus)

    hello

    Do you have access webserver logs?

    it’s accessible via cpanel/plesk or using ftp client ( usually log file in /public_html)

    thanks, Alex

    • This reply was modified 2 years, 1 month ago by algol.plus.

    Hi Alex, I’m developing locally.

    Using the magic of Xdebug, it was tracked down to this:

    make_new_settings expects an array like $in = array('settings' => [settings]); but it is receiving an array like array("json" => "{\"settings\": [settings]}")

    Plugin Author algol.plus

    (@algolplus)

    hi

    thank you for detailed reply.

    could you edit file classes/class-wc-order-export-admin.php ?
    find line
    $json = json_decode( $_POST[‘json’], true );
    and add below it
    var_dump(json_last_error_msg(), $json );die();

    what error will you get ?

    thanks, Alex

    • This reply was modified 2 years, 1 month ago by algol.plus.

    I’m not seeing any errors but I’m seeing an ajax request being cancelled (500 error)

    Plugin Author algol.plus

    (@algolplus)

    hi

    I’m sorry for inconvenience.

    after adding debug line, I have these lines

     $json = json_decode( $_POST['json'], true );
     var_dump(json_last_error_msg(), $json );die();
     if( is_array($json) ) {

    button Preview produces following output

    string(8) "No error"
    array(4) {
      ["settings"]=>
      array(55) {
        ["title"]=>.....
    

    Could you enable WP_DEBUG in wp-config.php?
    and add ini_set( ‘display_errors’, 1 );
    at top of file classes/class-wc-order-export-admin.php

    thanks, Alex

    Hi Alex,

    In my opinion, having the $_POST overridden in the first place is making the debug process a headache (how were we ever to know $_POST should have been overridden without reading the entire plugin?). However, the issue here appears to be that the JSON is wrapped in an extra set of quotes.

    The form data being sent by JavaScript looks like this:

    json="{"settings":""}" which results in json_decode() returning a string that looks like {"settings":""}

    Additionally, stripslashes_deep doesn’t do exactly what is needed to parse this string, as there is an issue parsing "\"" from the slashes. It should use wp_unslash instead.

    The following is the code that allows me to properly save settings — though I still recommend not overriding $_POST!

    
    $_POST = array_map('stripslashes_deep', $_POST);
    
    // parse json to arrays?
    if ( ! empty( $_POST['json'] ) ) {
    	$json_string = trim( $_POST['json'], '"');
    	$json_string = wp_unslash( $json_string );
    
    	$json = json_decode( $json_string, true );
    
    	if(is_array($json)) {
    		$_POST = $_POST + $json;
    		unset( $_POST['json'] );
    	}
    }
    
    • This reply was modified 2 years, 1 month ago by johnrom.
    • This reply was modified 2 years, 1 month ago by johnrom.
    • This reply was modified 2 years, 1 month ago by johnrom.
    Plugin Author algol.plus

    (@algolplus)

    hi John

    only few users has this problem and json="{"settings":""}" is wrong. Probably, it’s error in javascript.

    Could you check what string browser sends to WordPress back-end ?
    I see in Chrome DevTools json:{"settings":{..}}.

    thanks, Alex

    johnrom

    (@johnrom)

    Hi Alex,

    It looks like another plugin was changing the version of jquery-serialize-object, and removing that plugin fixed things. Thanks for your help!

    John

    Plugin Author algol.plus

    (@algolplus)

    hi John

    What plugin exactly? I have to fix this issue, other users might have same problem.

    thanks, Alex

    johnrom

    (@johnrom)

    Hi Alex,

    It was not a public plugin. I don’t think plugins should be switching out custom versions of WordPress-provided jQuery plugins, so I personally wouldn’t worry about this issue.

    If you really think it is necessary to fix, you can test the functionality by adding an action to wp_enqueue_scripts where you enqueue a custom version of jquery-serialize-object. Something like this should work:

    
    function algol_custom_assets() {
        
        wp_enqueue_script( 
            'custom-serialize-object', 
            'https://cdnjs.cloudflare.com/ajax/libs/jquery-serialize-object/2.4.5/jquery.serialize-object.min.js', 
            array('jquery'), 
            '2.4.5', 
            true 
        );
    }
    add_action('wp_enqueue_scripts', 'algol_custom_assets') );
    

    Then you should test if $_POST['json'] starts with ", and if so, run the commands I wrote in my previous comment.

    
    $json_string = trim( $_POST['json'], '"');
    $json_string = wp_unslash( $json_string );
    
    $json = json_decode( $json_string, true );
    

    John

    P.S., if they override jquery-serialize-object, Woo product variations no longer work either so exporting could be the least of the user’s problems.

    • This reply was modified 2 years ago by johnrom.
    • This reply was modified 2 years ago by johnrom.
    Plugin Author algol.plus

    (@algolplus)

    hi John

    I reproduced this error.

    I modified function “script_loader_src” in file classes/class-wc-order-export-admin.php
    to prevent loading this script on my pages

    now it looks like

    	public function script_loader_src($src, $handle) {
    		// don't load ANY select2.js / select2.min.js  and OUTDATED select2.full.js
    		if (!preg_match('/\/select2\.full\.js\?ver=[1-3]/', $src) && !preg_match('/\/select2\.min\.js/', $src) && !preg_match('/\/select2\.js/', $src) 
    		    && !preg_match('#jquery\.serialize-object\.#', $src)  /*this script breaks our json!*/
    		) {
    			return $src;
    		}
    	}
    

    thank you for really useful replies.

    • This reply was modified 2 years ago by algol.plus.
    Plugin Author algol.plus

    (@algolplus)

    This modification was included in version 1.5.4

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Settings are not saved’ is closed to new replies.