Plugin Directory

Changeset 3260503


Ignore:
Timestamp:
03/24/2025 02:52:43 AM (11 months ago)
Author:
ipodguy79
Message:

Updated to version 2.2 – new settings UI, admin SKU hiding, review prompt, passes Plugin Check

Location:
hide-sku-from-customer
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • hide-sku-from-customer/trunk/hide-sku-from-customer.php

    r3086749 r3260503  
    22/*
    33Plugin Name:  Hide SKU From Customer
    4 Description:  Remove SKU from Users view while still able to use for admin purposes.
    5 Version:      1.0
     4Description:  Hide product SKUs from non-admins while preserving admin access. Now includes admin settings to toggle visibility and even hide from admins on the front end.
     5Version:      2.2
    66Author:       sacredcactus
    77Author URI:   https://github.com/ipodguy79
    88License:      GPL2
    99License URI:  https://www.gnu.org/licenses/gpl-2.0.html
    10 Text Domain:  Hide-SKU-From-Customer
    11 Domain Path:  /languages
     10Text Domain:  hide-sku-from-customer
     11Requires at least: 5.8
     12Tested up to: 6.7
     13Requires PHP: 7.2
     14WC requires at least: 5.0
     15WC tested up to: 8.6
    1216*/
    1317
    14 function sv_remove_product_page_skus( $enabled ) {
    15     if ( ! is_admin() && is_product() ) {
     18defined( 'ABSPATH' ) || exit;
     19
     20/**
     21 * Add settings section to WooCommerce > Products.
     22 */
     23function sc_hide_sku_settings_init() {
     24    add_filter( 'woocommerce_get_settings_products', 'sc_hide_sku_add_settings', 99 );
     25}
     26add_action( 'admin_init', 'sc_hide_sku_settings_init' );
     27
     28/**
     29 * Register custom settings under WooCommerce > Settings > Products
     30 */
     31function sc_hide_sku_add_settings( $settings ) {
     32    $new_settings = array();
     33
     34    $new_settings[] = array(
     35        'title'    => __( 'Hide SKU From Customer', 'hide-sku-from-customer' ),
     36        'type'     => 'title',
     37        'desc'     => '',
     38        'id'       => 'sc_hide_sku_options',
     39    );
     40
     41    $new_settings[] = array(
     42        'title'    => __( 'Hide SKU from non-admins', 'hide-sku-from-customer' ),
     43        'desc'     => __( 'If checked, SKUs will be hidden from customers and only visible to admins or shop managers.', 'hide-sku-from-customer' ),
     44        'id'       => 'sc_hide_sku_enabled',
     45        'type'     => 'checkbox',
     46        'default'  => 'yes',
     47        'desc_tip' => true,
     48    );
     49
     50    $new_settings[] = array(
     51        'title'    => __( 'Also hide SKU from admins (front end)', 'hide-sku-from-customer' ),
     52        'desc'     => __( 'If checked, SKUs will be hidden for everyone — including admins — on the front end.', 'hide-sku-from-customer' ),
     53        'id'       => 'sc_hide_sku_hide_admins_front',
     54        'type'     => 'checkbox',
     55        'default'  => 'no',
     56        'desc_tip' => true,
     57    );
     58
     59    $new_settings[] = array(
     60        'type' => 'sectionend',
     61        'id'   => 'sc_hide_sku_options',
     62    );
     63
     64    return array_merge( $settings, $new_settings );
     65}
     66
     67/**
     68 * Save our custom SKU hiding settings
     69 */
     70function sc_hide_sku_save_settings() {
     71    $settings = sc_hide_sku_add_settings( [] );
     72    WC_Admin_Settings::save_fields( $settings );
     73}
     74add_action( 'woocommerce_update_options_products', 'sc_hide_sku_save_settings' );
     75
     76/**
     77 * Determine if SKU should be hidden
     78 */
     79function sc_should_hide_sku() {
     80    $enabled     = get_option( 'sc_hide_sku_enabled', 'yes' );
     81    $hide_admins = get_option( 'sc_hide_sku_hide_admins_front', 'no' );
     82
     83    if ( $enabled !== 'yes' ) {
    1684        return false;
    1785    }
    1886
    19     return $enabled;
    20 }
    21 add_filter( 'wc_product_sku_enabled', 'sv_remove_product_page_skus' );
     87    if ( is_admin() ) {
     88        return false; // Always allow SKUs in wp-admin
     89    }
     90
     91    if ( current_user_can( 'manage_woocommerce' ) && $hide_admins !== 'yes' ) {
     92        return false;
     93    }
     94
     95    return true;
     96}
     97
     98/**
     99 * Disable SKU setting for frontend product pages
     100 */
     101function sc_hide_sku_for_customers( $enabled ) {
     102    return sc_should_hide_sku() ? false : $enabled;
     103}
     104add_filter( 'wc_product_sku_enabled', 'sc_hide_sku_for_customers' );
     105
     106/**
     107 * Hide SKU values directly (for theme/template access)
     108 */
     109add_filter( 'woocommerce_product_get_sku', function( $sku, $product ) {
     110    return sc_should_hide_sku() ? '' : $sku;
     111}, 10, 2 );
     112
     113add_filter( 'woocommerce_product_variation_get_sku', function( $sku, $variation ) {
     114    return sc_should_hide_sku() ? '' : $sku;
     115}, 10, 2 );
     116
     117/**
     118 * Add admin bar badge only if SKUs are hidden from admins
     119 */
     120function sc_add_admin_bar_sku_admin_notice( $wp_admin_bar ) {
     121    if ( ! is_admin() && current_user_can( 'manage_woocommerce' ) ) {
     122        if ( get_option( 'sc_hide_sku_hide_admins_front', 'no' ) === 'yes' ) {
     123            $wp_admin_bar->add_node( array(
     124                'id'    => 'sc-sku-hider-status',
     125                'title' => 'SKUs Hidden from Admin',
     126                'meta'  => array( 'class' => 'sc-sku-active' ),
     127            ) );
     128        }
     129    }
     130}
     131add_action( 'admin_bar_menu', 'sc_add_admin_bar_sku_admin_notice', 100 );
     132
     133/**
     134 * Style the admin bar badge (green highlight)
     135 */
     136function sc_sku_admin_bar_styles() {
     137    if ( is_admin() ) return;
     138
     139    if ( current_user_can( 'manage_woocommerce' ) ) {
     140        echo '<style>
     141            #wpadminbar #wp-admin-bar-sc-sku-hider-status > .ab-item {
     142                background-color: #2ecc71;
     143                color: #fff !important;
     144                font-weight: bold;
     145                padding: 0 10px;
     146                border-radius: 4px;
     147            }
     148        </style>';
     149    }
     150}
     151add_action( 'wp_head', 'sc_sku_admin_bar_styles' );
     152
     153/**
     154 * Store install time if not already set
     155 */
     156function sc_record_install_time() {
     157    if ( ! get_option( 'sc_hide_sku_install_time' ) ) {
     158        update_option( 'sc_hide_sku_install_time', time() );
     159    }
     160}
     161register_activation_hook( __FILE__, 'sc_record_install_time' );
     162
     163/**
     164 * Show review notice after 30 days
     165 */
     166function sc_maybe_show_review_notice() {
     167    if ( ! current_user_can( 'manage_woocommerce' ) ) return;
     168    if ( get_option( 'sc_hide_sku_review_dismissed' ) === 'yes' ) return;
     169
     170    $installed = get_option( 'sc_hide_sku_install_time' );
     171    if ( ! $installed || ( time() - $installed ) < ( 30 * DAY_IN_SECONDS ) ) return;
     172
     173    $review_url  = 'https://wordpress.org/plugins/hide-sku-from-customer/#reviews';
     174    $dismiss_url = wp_nonce_url(
     175        add_query_arg( 'sc_hide_sku_dismiss_review', '1' ),
     176        'sc_hide_sku_review_dismiss',
     177        '_scsku_nonce'
     178    );
     179
     180    echo '<div class="notice notice-success is-dismissible sc-hide-sku-review-notice">';
     181    echo '<p>';
     182    echo 'Enjoying <strong>Hide SKU From Customer</strong>? Please <a href="' . esc_url( $review_url ) . '" target="_blank" rel="noopener noreferrer">leave a ★★★★★ review</a> to support us!';
     183    echo ' &nbsp; <a href="' . esc_url( $dismiss_url ) . '">Dismiss</a>';
     184    echo '</p>';
     185    echo '</div>';
     186}
     187add_action( 'admin_notices', 'sc_maybe_show_review_notice' );
     188
     189/**
     190 * Handle review dismissal (secure)
     191 */
     192function sc_handle_review_dismissal() {
     193    if ( isset( $_GET['sc_hide_sku_dismiss_review'] ) && isset( $_GET['_scsku_nonce'] ) ) {
     194        $nonce = isset( $_GET['_scsku_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_scsku_nonce'] ) ) : '';
     195if ( wp_verify_nonce( $nonce, 'sc_hide_sku_review_dismiss' ) ) {
     196            update_option( 'sc_hide_sku_review_dismissed', 'yes' );
     197        }
     198    }
     199}
     200add_action( 'admin_init', 'sc_handle_review_dismissal' );
  • hide-sku-from-customer/trunk/readme.txt

    r3086749 r3260503  
    1 === Hide SKU's From Customers ===
     1=== Hide SKU From Customer ===
    22Contributors: ipodguy79
    3 Tags: SKU, Product Managemen, Product Information, Hide SKU
    4 Requires at least: 5.0
    5 Tested up to: 6.5.2
    6 Stable tag: 1.0
     3Tags: SKU, WooCommerce, Product Management, Hide SKU, Inventory
     4Requires at least: 5.8
     5Tested up to: 6.7
     6Requires PHP: 7.2
     7Stable tag: 2.2
    78License: GPLv2 or later
    89License URI: http://www.gnu.org/licenses/gpl-2.0.html
    9  
    10 WooCommerce SKU Visibility plugin allows you to hide product SKUs from customers  
     10
     11WooCommerce SKU Visibility plugin allows you to hide product SKUs from customers while retaining full functionality for store admins.
    1112
    1213== Description ==
    13  
    14 WooCommerce SKU Visibility plugin allows you to hide product SKUs from customers while retaining their functionality for admins on the admin dashboard. Improve the user experience by decluttering product pages while maintaining inventory management efficiency."
    15  
     14
     15Hide SKU From Customer is a lightweight plugin that lets you remove SKU display from the front end of your WooCommerce store for customers — while keeping it fully functional for admin users.
     16
     17As of version 2.2, this plugin includes admin settings under **WooCommerce → Settings → Products** that let you:
     18- ✅ Enable or disable SKU hiding
     19- ✅ Optionally hide SKU display for **admins on the front end** as well
     20- ✅ See a small green admin bar badge when the feature is active
     21
     22Perfect for stores that use SKUs internally but don’t want to display them to customers on product pages, loops, quick view, etc.
     23
    1624== Installation ==
    17  
    18 1. Upload the plugin folder to your /wp-content/plugins/ folder.
    19 1. Go to the **Plugins** page and activate the plugin.
    20  
     25
     261. Upload the plugin folder to your `/wp-content/plugins/` directory.
     272. Activate the plugin via the **Plugins** page in WordPress.
     283. Go to **WooCommerce → Settings → Products** to configure the SKU visibility settings.
     29
    2130== Frequently Asked Questions ==
    22  
     31
    2332= How do I use this plugin? =
    24  
    25 Just activate it and your done there is no settings.
    26  
    27 = How to uninstall the plugin? =
    28  
    29 Simply deactivate and delete the plugin.
    30  
     33
     34Just activate the plugin. By default, it hides SKUs for customers but still shows them to admin and shop manager users. Go to **WooCommerce → Settings → Products** to configure visibility.
     35
     36= How do I hide SKUs even from admins on the front end? =
     37
     38Enable the "Also hide SKU from admins (front end)" checkbox in the plugin settings.
     39
     40= Does this affect inventory tracking or SKU functionality? =
     41
     42No. It only hides the **visual display** of SKUs on the front end. Everything else (backend, orders, inventory, etc.) continues to work normally.
     43
     44= How do I uninstall the plugin? =
     45
     46Simply deactivate and delete it from the Plugins page. No data is left behind.
     47
    3148== Screenshots ==
    32 1. notice sku highlighted
    33 2. notice sku is missing (highlighted)
    34  
    35  
     491. SKU visible with plugin disabled
     502. SKU hidden with plugin enabled
     513. Admin settings page with visibility toggles
     524. Green admin bar badge indicating the plugin is active
     53
    3654== Changelog ==
     55
     56= 2.2 =
     57* Admin bar badge now only displays if “hide from admins” is enabled
     58* Removed unnecessary status message when only hiding from customers
     59
     60= 2.1 =
     61* Added settings under WooCommerce → Products to toggle SKU visibility
     62* New option to also hide SKUs from admins on the front end
     63* Admin bar badge displays when SKU hiding is active
     64* Settings now save correctly and persist
     65
    3766= 1.0 =
    38 * Plugin released.
     67* Initial release
Note: See TracChangeset for help on using the changeset viewer.