#1 2019-05-29 16:47:57

PHP Phrog

Easily Reorder The Store Dropdown List in PremiumPress

Note:  This example was created to work with the Coupon Theme specifically for the Add Coupon page.

You can easily reorder the coupon store list ascending alphabetically by placing this function in the _functions.php file.

function _ascending_storelist() {
        global $post;
        // Make sure it's the "Add Coupon" page before adding.
        if( 'add-listing' !== $post->post_name) { return; }
    var options = jQuery('select#reg_field_tax_store option');
    var arr = options.map(function(_, o) { return { t: jQuery(o).text(), v: o.value }; }).get();
    arr.sort(function(o1, o2) { var t1 = o1.t.toLowerCase(), t2 = o2.t.toLowerCase(); return o1.t > o2.t ? 1 : o1.t < o2.t ? -1 : 0; });
    options.each(function(i, o) { o.value = arr[i].v; jQuery(o).text(arr[i].t); });
add_action('wp_footer', '_ascending_storelist');

This function should work with all "Store" lists in general (not just for coupon theme), however you may need to change the jQuery selector select#reg_field_tax_store' to the name of the proper element. Also, if the dropdown is on a different page, other than the add-lising, then be sure to change it to the current page the dropdown is on.


Board footer

Powered by FluxBB