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;
  }

 

Leave a Reply

Your email address will not be published. Required fields are marked *