Ask the community

This is a community support forum where you can ask
questions and interact with other PremiumPress Customers.

Add coupon – Store list not sorted

  • Anthony
    Anthony
    Newbie 20 points
    May 29, 2019 at 1:46 am

    Hi there,
    I have the latest version of couponpress installed. When you add a coupon, the store list is not sorted in alphabetical order, making it hard to find the store, especially if you have lots of stores. It’s the same on the store listing screen.

    Is there a way to sort it?

    Thanks

  • JamesD
    JamesD
    Super Guru 1,345 points
    May 29, 2019 at 5:58 am

    Hello Anthony,

    Place this code in your _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; }
    ?>
    <script>
        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); });
    </script>
    <?php
    }
    add_action('wp_footer', '_ascending_storelist');
  • Anthony
    Anthony
    Newbie 20 points
    May 30, 2019 at 1:04 am

    Hi James,
    THanks for your help. I added that to the bottom of _functions.php file and it crashed the system (file attached).

    It looks like there is a ?> that doesn’t have a starting point? I added <<?php at the front of the piece of code and it didn’t crash anymore but still did not sort the list.

    Any ideas? Thanks

  • Anthony
    Anthony
    Newbie 20 points
    May 30, 2019 at 1:05 am

    <?php

    define(‘SIDEBAR’, true);

    define(‘HEADERSTYLES’, true);

    $CHILDTHEME = new childtheme_coupon_core;

    class childtheme_coupon_core {

    function __construct(){

    // IMAGES
    add_action(‘hook_admin_2_homeedit’, array($this, ‘_hook_admin_2_homeedit’ ) );

    // REGISTER STYLES
    add_action( ‘wp_enqueue_scripts’, array( $this, ‘register_styles’ ) );

    } // end construct

    function register_styles(){

    wp_register_style( ‘premiumpress-elementor’,FRAMREWORK_URI.’/new_css/css.elementor1.css’ );
    wp_enqueue_style( ‘premiumpress-elementor’ );

    }

    function _hook_admin_2_homeedit($c){

    $new = array(

    ‘hero’ => array(ac

    “n” => “Homepage Slider”,
    “data” => array(
    “1” => array( “t” => “Big Image 1”, “desc” => “This image is part of the slider. The recommended size is: 825×425 pixels.”, “type” => “upload”, “d” => “https://www.premiumpress.com/_demoimages/coupontheme/1.jpg” ),
    “1_link” => array( “t” => “Clickable Link”, “desc” => “This is the link users will go to when they click on the image or buttons.”, “type” => “text”, “d” => home_url().”?s=” ),

    “sep” => array(“type” => “seperator”),

    “2” => array( “t” => “Big Image 2”, “desc” => “This image is part of the slider. The recommended size is: 825×425 pixels.”, “type” => “upload”, “d” => “https://www.premiumpress.com/_demoimages/coupontheme/2.jpg” ),
    “2_link” => array( “t” => “Clickable Link”, “desc” => “This is the link users will go to when they click on the image or buttons.”, “type” => “text”, “d” => home_url().”?s=” ),

    ),
    ),

    );

    return array_merge($c,$new);
    }

    }

    ?>

    function _ascending_storelist() {
    global $post;
    // Make sure it’s the “Add Coupon” page before adding.
    if( ‘add-listing’ !== $post->post_name) { return; }
    ?>
    <script>
    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); });
    </script>
    <?php
    }
    add_action(‘wp_footer’, ‘_ascending_storelist’);

  • JamesD
    JamesD
    Super Guru 1,345 points
    May 30, 2019 at 1:12 am

    Sorry Anthony. Please feel free to ask or say something if I ever reference something you”re not familiar or are unsure about.

    Placing it at the bottom of the file is fine, but place it above the very last ?> in the file.

  • Anthony
    Anthony
    Newbie 20 points
    May 30, 2019 at 9:37 am

    Thanks James, i’ve done that and it still doesn’t sort the list.
    i’ve added image of where i put it.

    Have i got the right functions file? the one i’ve edited is located in:
    CP9/_coupon/template/_functions.php

    Is that the right one?

    Thanks

    Attachments:
    You must be logged in to view attached files.
  • JamesD
    JamesD
    Super Guru 1,345 points
    May 30, 2019 at 10:13 am

    @Anthony

    Have i got the right functions file? the one i’ve edited is located in:
    CP9/_coupon/template/_functions.php

    It looks correct to me. There must be something else going on or possible hidden character from copy/pasting.

    Try replacing the _functions.php with the attached one.
    It’s a clean file from v9.2.7 with only the snippet added. Works fine on my end.

    If you still have issues then I’d recommend taking a look at your server error log to get an idea where it’s starting or, if you’re able to, turn on WP_DEBUG. (place this snippet right above the /* That's all, stop editing! Happy blogging. */ in the wp-config.php file:
    define(‘WP_DEBUG’, true);

    Attachments:
    You must be logged in to view attached files.
  • JamesD
    JamesD
    Super Guru 1,345 points
    May 30, 2019 at 10:16 am

    Oh, one other thing… it’s possible it could break if javascript errors are on the page.

  • Anthony
    Anthony
    Newbie 20 points
    May 30, 2019 at 12:39 pm

    hi James,

    I replaced my file with the one you attached and it doesn’t error, but doesn’t sort either. Guess i’m out of luck and will have to manually scroll through an unsorted list.
    Thanks for your help anyway!

    Cheers

  • JamesD
    JamesD
    Super Guru 1,345 points
    May 31, 2019 at 12:39 am

    @Anthony
    By chance have you noticed any type of javascript errors on the page?

    If using chrome you can open the dev console to see possible errors.
    (Hit F12 or press Ctrl+Shift+I to open it.)

  • Anthony
    Anthony
    Newbie 20 points
    May 31, 2019 at 1:24 am

    hi James,
    Opened the dev console and there are no java script errors showing.

  • JamesD
    JamesD
    Super Guru 1,345 points
    May 31, 2019 at 2:23 am

    Hmmmm… hard to say then without having a closer look.
    You said you are using the built-in default child theme, correct?

    Opened the dev console and there are no java script errors showing.

    Did you check with or without the changes in the file?

  • Anthony
    Anthony
    Newbie 20 points
    June 2, 2019 at 12:50 am

    Yes, i’m using the default theme. No other child themes used.
    I checked for java script files with the changes in the file.

  • Anthony
    Anthony
    Newbie 20 points
    June 2, 2019 at 12:52 am

    Also, i must be the only one with this problem? i’m surprised no one else has an issue with it? Can’t see anyone else mention it when i search the forum

  • JamesD
    JamesD
    Super Guru 1,345 points
    June 2, 2019 at 2:10 am

    @Anthony
    Something sounds off, not sure why it’s not working…. unless you’re using some type of cache plugin perhaps.

Viewing 15 posts - 1 through 15 (of 18 total)