Allow instructors to create WooCommerce coupons

By default Instructor user role can not create WooCommerce coupons. Following tip will help you in allowing instructors to create coupons in your site via WP Admin interface:

a. Paste below code in Child Theme functions.php or Wplms customiser – wplms_customiser.php

b. After pasting the code login as instructor and refresh the WP Admin screen twice and you should see a coupons link in the WP Admin menu.

add_action( 'admin_init','enable_instructor_to_create_coupons');
    function enable_instructor_to_create_coupons(){
      $role = get_role( 'instructor' );
      $capabilities = wplms_get_woocommerce_core_capabilities();
        
        foreach ( $capabilities as $cap_group ) {
          foreach ( $cap_group as $cap ) {
            $role->add_cap( $cap );
          }
        }
    }
    function wplms_get_woocommerce_core_capabilities() {
    $capabilities = array();

    $capability_types = array( 'shop_coupon');

    foreach ( $capability_types as $capability_type ) {

      $capabilities[ $capability_type ] = array(
        // Post type
        "edit_{$capability_type}",
        "read_{$capability_type}",
        "delete_{$capability_type}",
        "edit_{$capability_type}s",
        "publish_{$capability_type}s",
        "read_private_{$capability_type}s",
        "delete_{$capability_type}s",
        "delete_private_{$capability_type}s",
        "delete_published_{$capability_type}s",
        "edit_private_{$capability_type}s",
        "edit_published_{$capability_type}s",
      );
    }

    return $capabilities;
  }

 

Was this article helpful?

Related Articles

7 Comments

  1. foxycleop

    This allows any instructor access to create coupons for any course on the website?

      1. foxycleop

        I think instructors should be able to create coupons for their own courses not courses from other instrcutors. Is that possible?

  2. hemant_832003

    Please add feature “Instructor can create coupon code from frontend for his course”

    Thanks

  3. terracotta

    one more:

    Please add feature “Instructor can create coupon code from frontend for his course”

    Thanks

Leave A Comment?