[英]Replace Product SKU Based on product Title in Order Details Page
I am trying to append text to the SKU when a sample is ordered.我正在尝试在订购样品时将文本附加到 SKU。
I have tried the following code to modify the title,我尝试了以下代码来修改标题,
function cart_title($title, $values, $cart_item_key){
if ($values['sample']){
$title .= ' [' . __('Sample','woosample') . '] ';
}
return $title;
}
How do I modify this code to change the SKU?如何修改此代码以更改 SKU?
note: woocommerce_cart_item_name will not display in the backend order view
注意:woocommerce_cart_item_name 不会显示在后端订单视图中
function cart_title( $title, $cart_item, $cart_item_key ) {
$product = $cart_item['data'];
$product_sku = $product->get_sku();
// optional
if ( empty( $product_sku ) ) {
$product_sku = 'not found!';
}
$title = $title . ' + ' . $product_sku;
return $title;
}
add_filter('woocommerce_cart_item_name', 'cart_title', 10, 3 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.