how can i add the coupon option in the dashboard?

i would like to add the coupon option in the dashboard . how can i make this happen?pls advise

  • Luís Lopes
    • QA

    Hi @jacques,

    I hope had been good today!

    Firstly, sorry for my late reply and all the problems it may have caused.

    I think your are trying to add the Coupons as a Top Level menu, instead of a subitem of the Store item.

    If yes, please try add this code to your theme functions.php

    //remove the subitem

    add_action( 'admin_menu', 'adjust_the_wp_menu', 999 );

    function adjust_the_wp_menu() {

    $page = remove_submenu_page( 'edit.php?post_type=' . MP_Product::get_post_type(), 'edit.php?post_type=mp_coupon' );

    }

    //add Coupons as a Top Level menu item

    add_action( 'admin_menu', 'coupons_top_level' );

    function coupons_top_level() {

    add_menu_page( 'Coupons', 'Coupons', apply_filters( 'mp_coupons_capability', 'edit_mp_coupons' ), 'edit.php?post_type=mp_coupon');

    }

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • jacques
    • The Crimson Coder

    Hey Luis. Thank you for the reply. Here I want to put the coupon in the same area as store setting ,sales , status , account space and so on. Not on the side bar. I want it to be the main priority for the concept I a trying to promote

  • jacques
    • The Crimson Coder

    thanks for the reply. ok i want to add the coupon option in the screen option so it can actually show in the dashboard like the rest of the option in the screen options.

    also when i click in the dashboard in the main site it goes to the user profile page and not to the dashboard page. any idea on how to do that?

  • Ash
    • Code Norris

    Hello @jacques

    I hope you are doing good.

    ok i want to add the coupon option in the screen option so it can actually show in the dashboard like the rest of the option in the screen options.

    I have read the full thread, but I am still confused, sorry. Do you want to show coupon as panel (marked with red border) in the screenshot?

    also when i click in the dashboard in the main site it goes to the user profile page and not to the dashboard page. any idea on how to do that?

    As this is a different than the topic title, would you please create a new thread for this? Please add more details about the issue, example urls and other details. It will help us to provide faster support and avoid delay :slight_smile:

    Have an awesome day!

    Cheers

    Ash

    [attachments are only viewable by logged-in members]

  • Ash
    • Code Norris

    Hello @jacques

    That makes sense, but it will need custom development. Would you please let me know what information about coupon you want to show there? Please note that, you can’t create/edit coupon from that red box. So, do you want to show created coupon as list or something else?

    Have an awesome day!

    Cheers

    Ash

  • Ash
    • Code Norris

    Hello @jacques

    When you say “want to show how to create/edit Coupon from the red box”, is this just instruction, or you want to create coupon from that box (that’s not possible just FYI)?

    If you just want to show instruction or list of coupons or even a button to create coupon in that red box, that’s possible.

    Please let me know.

    Cheers

    Ash

  • Ash
    • Code Norris

    Hi there

    Please try the following code:

    add_action( 'wp_dashboard_setup', 'coupons_add_dashboard_widget' );
    function coupons_add_dashboard_widget() {
    if( post_type_exists( 'mp_coupon' ) ) {
    wp_add_dashboard_widget(
    'coupons_add_dashboard_widget',
    'Coupons',
    'coupons_add_dashboard_widget_function'
    );
    }
    }

    function coupons_add_dashboard_widget_function() {
    ?>
    <h4>Title about coupon</h4>
    <p>This is some instruction. This is some instruction. This is some instruction. This is some instruction. This is some instruction. This is some instruction.</p>
    <p>This is some instruction. This is some instruction. This is some instruction. This is some instruction. This is some instruction. This is some instruction.</p>
    <h4>Created Coupon</h4>
    <?php
    $args = array(
    'posts_per_page' => -1,
    'post_type' => 'mp_coupon',
    'post_status' => 'publish'
    );
    $posts = get_posts( $args );
    $coupons = array();
    foreach( $posts as $post ) {
    $coupons[] = $post->post_title;
    }

    echo implode( ', ', $coupons );
    ?>
    <p>
    <a class="button button-primary" href="<?php echo admin_url( 'post-new.php?post_type=mp_coupon' ) ?>">Create a coupon</a>
    </p>
    <?php
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name ‘mu-plugins’. If there is no folder in that name, then create a folder, name it ‘mu-plugins’, create a file inside that, give any name you like and paste the code in there. You don’t need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers

    Ash