Skip to content

Instantly share code, notes, and snippets.

@d4mation
Created November 1, 2022 18:50
Show Gist options
  • Select an option

  • Save d4mation/90e44828f2322a9ea8ab7e25f804c71f to your computer and use it in GitHub Desktop.

Select an option

Save d4mation/90e44828f2322a9ea8ab7e25f804c71f to your computer and use it in GitHub Desktop.

Revisions

  1. d4mation created this gist Nov 1, 2022.
    35 changes: 35 additions & 0 deletions eddar-auto-populate.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    // Just run this in the console and you're good to go

    var firstOption = true;

    jQuery( 'select[name="edd_report_series[0][download]"] option' ).each( function( index, option ) {

    if ( jQuery( option ).val() == 0 || jQuery( option ).val() == 'all' ) return true;

    if ( firstOption ) {

    var $row = jQuery( option ).closest( '.eddar-collection-row' );

    firstOption = false;

    }
    else {

    jQuery( '.eddar-collection-add-row' ).click();

    var $row = jQuery( '.eddar-collection-row' ).last();

    }

    $row.find( 'select[name*="context"]' ).val( 'earnings_gross' ).trigger( 'change' );
    $row.find( 'select[name*="download"]' ).val( jQuery( option ).val() ).trigger( 'change' ).trigger( 'chosen:updated' );
    $row.find( 'select[name*="status"]' ).val( 'complete' ).trigger( 'change' );

    jQuery( '.eddar-collection-add-row' ).click();
    $row = jQuery( '.eddar-collection-row' ).last();

    $row.find( 'select[name*="context"]' ).val( 'earnings_gross' ).trigger( 'change' );
    $row.find( 'select[name*="download"]' ).val( jQuery( option ).val() ).trigger( 'change' ).trigger( 'chosen:updated' );
    $row.find( 'select[name*="status"]' ).val( 'edd_subscription' ).trigger( 'change' );

    } );