Title: Exclude php function
Last modified: February 27, 2020

---

# Exclude php function

 *  [ondrej.krejc](https://wordpress.org/support/users/ondrejkrejc/)
 * (@ondrejkrejc)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/exclude-php-function/)
 *     ```
       function skyverge_shop_display_skus() {	
   
       	global $product;
   
       	if ( $product->get_sku() ) {
       		echo '<div class="product-meta">SKU: ' . $product->get_sku() . '</div>';
       	} elseif ( $product->get_available_variations() ) {
           $available_variations = $product->get_available_variations();
         	echo '<div class="product-meta-sku">';
       		for ( $i = 0; $i < count($available_variations); $i++ ) {
       			if ( $available_variations[$i]['sku'] ) {
       		    echo ($available_variations[$i]['sku']);
       		    if ( $i < (count($available_variations) - 1) ) {
       		      echo ', ';
       		    }
       			}
       		}
          	echo '</div>';
       	}
       }
       add_action( 'woocommerce_after_shop_loop_item_title', 'skyverge_shop_display_skus', 9 );  
       ```
   
 * I have this function, but i need exclude this function on same category pages,
   because on some pages giving me error.
 * Is it possible?

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/exclude-php-function/#post-12572763)
 * Hey [@ondrejkrejc](https://wordpress.org/support/users/ondrejkrejc/),
 * Can you clarify what you mean by ‘same category’ pages?
 * If you mean on specific category archives, you can use the [is_category()](https://developer.wordpress.org/reference/functions/is_category/)
   function for that purpose.
 * For example, if you wanted to prevent the function from running on the category
   with the ID `142` or with the slug `cats`, you would add this at the beginning
   of the function:
 *     ```
       if ( is_category( [ 42, 'cats' ] ) ) {
       	return;
       }
       ```
   
 * However, you could also try this. It should prevent an error from occurring by
   checking if the `$product` variable exists before attempting to use it:
 *     ```
       add_action( 'woocommerce_after_shop_loop_item_title', function () {
       	global $product;
   
       	if ( ! isset( $product ) ) {
       		return;
       	}
   
       	if ( $product->get_sku() ) {
       		echo '<div class="product-meta">SKU: ' . $product->get_sku() . '</div>';
       	} elseif ( $product->get_available_variations() ) {
       		$available_variations = $product->get_available_variations();
       		echo '<div class="product-meta-sku">';
       		for ( $i = 0; $i < count($available_variations); $i++ ) {
       			if ( $available_variations[$i]['sku'] ) {
       				echo ($available_variations[$i]['sku']);
       				if ( $i < (count($available_variations) - 1) ) {
       					echo ', ';
       				}
       			}
       		}
       		echo '</div>';
       	}
       }, 9 );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Exclude php function’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [6 years, 2 months ago](https://wordpress.org/support/topic/exclude-php-function/#post-12572763)
 * Status: not a support question