
In alcuni temi per WordPress, ottimizzati anche per WooCommerce, non viene mostrato il il codice ISKU (Stock Keeping Unit) nella pagina del carrello ed in quella del checkout.
Per risolvere il problema inseriremo all’interno del file functions.php del tema il codice seguente, che permetterà di mostrare il codice SKU anche per i prodotti variabili:
/* mostra il codice SKU nel carrello e nel checkout */
add_filter( ‘woocommerce_cart_item_name’, ‘showing_sku_in_cart_items’, 99, 3 );
function showing_sku_in_cart_items( $item_name, $cart_item, $cart_item_key ) {
// The WC_Product object
$product = $cart_item[‘data’];
if (empty($product)) {
return $item_name;
}
// Get the SKU
$sku = $product->get_sku();
// When sku doesn’t exist
if (empty($sku)) {
return $item_name;
}
// display the sku
$item_name .= ‘
‘ . __( “SKU: “, “woocommerce”) . $sku . ‘‘;
return $item_name;
}