if (! defined('WP_DEBUG')) {
die( 'Direct access forbidden.' );
}
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
});
// 重构 Checkout 名称列:带圆角描边的缩略图(铺满容器)+ 标题 + 数量;第二行属性
add_filter( 'woocommerce_cart_item_name', 'kofmee_checkout_layout_full_cover', 10, 3 );
function kofmee_checkout_layout_full_cover( $product_name, $cart_item, $cart_item_key ) {
if ( ! is_checkout() ) {
return $product_name;
}
$product = $cart_item['data'];
$qty = $cart_item['quantity'];
// 取标题:变体用父产品名
if ( $product->is_type( 'variation' ) && $product->get_parent_id() ) {
$parent = wc_get_product( $product->get_parent_id() );
$title = $parent ? $parent->get_name() : $product_name;
} else {
$title = $product_name;
}
// 取属性值
$variation = isset( $cart_item['variation'] ) ? $cart_item['variation'] : [];
$attrs = '';
if ( ! empty( $variation ) ) {
$vals = array_values( $variation );
$attrs = implode( ', ', $vals );
}
// 样式参数
$gap_px = 10; // 缩略图与标题之间的空隙
$indent_px = 70; // 属性行左侧缩进
$neg_mt = -18; // 属性行上移距离
$row_gap = 1; // 两行之间的基础间距
// 生成缩略图 HTML,并注入 IMG 样式
$thumb_html = $product->get_image( [60, 60] );
// 在 标签里添加 object-fit:cover 和 100% 宽高
$thumb_html = str_replace(
'
';
// 第一行:缩略图 + 标题 + 数量
$out .= '