Skip to content

Instantly share code, notes, and snippets.

@jamesckemp
Created September 19, 2019 10:57
Show Gist options
  • Save jamesckemp/e6e141f468e493aff99dbb880e20617b to your computer and use it in GitHub Desktop.
Save jamesckemp/e6e141f468e493aff99dbb880e20617b to your computer and use it in GitHub Desktop.
Show product SKU when searching in WooCommerce
<?php
/**
* Show SKU on products when searching.
*/
function iconic_show_sku_search() {
if ( ! is_search() ) {
return;
}
global $product;
$sku = $product->get_sku();
if ( empty( $sku ) ) {
return;
}
echo '<p>' . sprintf( '%s: %s', __( 'SKU', 'iconic' ), $sku ) . '</p>';
}
add_action( 'woocommerce_shop_loop_item_title', 'iconic_show_sku_search', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment