Created
September 19, 2019 10:57
-
-
Save jamesckemp/e6e141f468e493aff99dbb880e20617b to your computer and use it in GitHub Desktop.
Show product SKU when searching in WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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