You just need to change a bit your code this way, to get the SKU before the product name:
function show_sku_in_cart_items( $item_name, $cart_item, $cart_item_key ) {
// The WC_Product object
$product = $cart_item['data'];
// Get the SKU
$sku = $product->get_sku();
// When SKU doesn't exist
if ( empty( $sku ) )
return $item_name;
// Add SKU before
if ( is_cart() ) {
$item_name="<small class="product-sku">" . '<span class="sku-title">' . __( "SKU: ", "woocommerce") . '</span>' . $sku . '</small><br>' . $item_name;
} else {
$item_name="<small class="product-sku">" . $sku . '</small>' . $item_name;
}
return $item_name;
}
add_filter( 'woocommerce_cart_item_name', 'show_sku_in_cart_items', 99, 3 );
Related Posts:
- wc_get_template_part( ‘content’, ‘product’ ) | Where is this file located?
- how to get woocommerce product attribute slug
- How to display product price of the product in loop
- How to build a plugin that supports authenticated POST requests to the REST API from external servers?
- How do I add a text input field for customers to leave a note on a single WooCommerce product page?
- Where can I find a single item template
- Get Woocommerce Subscription Product
- WooCommerce pages accessible to logged in members only
- paypal not showing on woocommerce payments
- Target WooCommerce Product Gallery Image (rather than Featured Image) for og:image
- Stop WooCommerce from updating user/user meta after checkout
- Displaying Custom Input Value to Customer Order Details (My Account) page in Woocommerce
- Redirect user to cart page when add to cart button is clicked
- Woo API REST : product variation price is read-only?
- Get rid of product images mobile swipe functionality from WooCommerce single product [closed]
- How to upload Woocommerce product images via API? [closed]
- Problems with varibel price [closed]
- Custom Admin Email Subject for Woocommerce (3.8.0) Orders
- Woocommerce custom endpoints
- Tax Query for custom Taxonomy field
- Add Custom Slug Tags Per Page
- How to override Woocommerce functionality in Reports section?
- how can use woocommerce add to cart popup?
- Do I need a different product type for WooCommerce [closed]
- How to put Stripe first, PayPal second on the checkout page?
- How to change product thumbnail size in storefront theme
- Override static method in WC_Shortcodes class (shortcode) [closed]
- Show add to cart button and quantity field when no price is entered [closed]
- How to get woocommerce product collection in template file
- Results not being printed
- Remove ‘product’ & ‘product-cateogory’ from url – woocommerce [closed]
- display product’s category static slider name and image in loop wordpress
- Whitespace between product image and gallery on initial load of lightbox product page
- Why is my WordPress login credentials missing, but work with WooCommerce?
- Update Customer JWT Woocommerce
- Is there a hook in woocommerce for when a payment fails to display a custom error message?
- How to show notice alert only on product dashboard page?
- Retrieving Tag Name in Template Part from Filtered URL
- ajax request in wordpress
- Woocommerce product rewrite rules not working
- How to display a table below each product in product list/loop
- Woocommerce Canceled Order Notification email to admin
- separate functions for home VS other pages
- WooCommerce apply shipping rates based on price
- Extra items added to cart on refresh, woocommerce
- How disable some product features on woocomerce?
- WooCommerce – Split Multiple Items into Individual Line Items
- Hide sidebar and change layout Blog Page using is_page() function
- Woocommerce purchase date [closed]
- How to add a special Woocommerce “buy now” button?
- Woocommerce: Any way to list all products *without* a specific attribute?
- Filter by Price filter button not working
- porto theme pagination on woocommerce not working
- Adding preference buttons to main nav that persist via user sessions. (Woocommerce)
- How can I show “sold out” instead of “out of stock” for some products with particular tags and categories [closed]
- Woocommerce custom log in and register
- Assign user role by text field in WordPress (Woocommerce) [closed]
- Urgent Validate Save-Post Hooks on Woo-commerce product entry form!
- Is doing a database query in Woocommerce efficient to only display posts from a certain category?
- Call product search from custom hook
- How to get cookie value?
- Woocommerce Disabling Auto Restocking for Cancelled Orders
- Custom pagination permalink structure Product page
- MySQL error or data corruption after database migration
- My products are showing “not in stock” and I don’t know why
- Woocommerce change the price of products in the database
- Woocommerce modifying the html on the checkout page?
- Pseudo class :before don’t working in a specific button
- How to speed up “My Account > Orders Page” on Site with More than 200,000 orders?
- Editing product categories suddenly crashes website and goes back to wordpress installation
- “error_message”: “Sorry, you cannot list resources.” using WooCommerce API
- WooCommerce product details page category display
- Woocommerce – Default product image by user role
- WooCommerce product id as permalink
- Merge “description” and “additional informations” product tab
- WooCommerce does not translate every string
- Woocommerce add a text field if specific option is selected
- Add suffix to price html does not work
- Get user active posts randomly
- SyntaxError: unterminated string literal – if WordPress Debug in wp-config is set to true
- How Fragile Is DB if I Upload Completely Updated Files
- Broken 302 redirection for product subcategory (Woocommerce, Apache)
- Website Tablet Check Out Field Issue
- WooCommerce order created via REST – sending the date_created along
- How to allow registration only from a certain location?
- Add confirmation popup on place order button
- Get Third Level Categories WooCommerce
- Change WooCommerce Checkout Button – Reverts to normal
- Show pop up message for specific categoryies
- Send form data to functions.php
- How to remove content from hacked pages? [closed]
- Disable WooCommerce Address State Dropdown
- How to show detailed order history on woocommerce product page [closed]
- Can I remove WooCommerce specific product categories from shop managers?
- Fetch products with filter by similar categories at same time
- Trying query woocommerce product order by menu order and stock status
- editing product page template – getting template for related products not working
- Woocommerce | I want to the button ‘Add to Cart’ on the (all) product-page changed by just ‘open product’ button
- Disable Woocommerce Block Editor
- Woocommerce backend sorting product drag drop by menu_order to date