gpt4 book ai didi

php - 在 WooCommerce 快速订单预览窗口的新列中显示产品缩略图

转载 作者:行者123 更新时间:2023-12-04 07:36:01 38 4
gpt4 key购买 nike

如何在带有超链接的新列中显示产品缩略图,以便在单击时在新选项卡中打开缩略图?
列顺序:
“图像”、“产品”、“数量”
基于 Display product thumbnail in existing product column in WooCommerce quick order preview window回答代码,这是我的代码尝试:

function filter_woocommerce_admin_order_preview_line_item_columns( $columns, $order ) {
$new_product = $columns['image'];


return array_merge( array( 'new_product' => $new_product ), $columns );
}
add_filter( 'woocommerce_admin_order_preview_line_item_columns', 'filter_woocommerce_admin_order_preview_line_item_columns', 10, 2 );

function filter_woocommerce_admin_order_preview_line_item_column_new_product( $html, $item, $item_id, $order ) {
$hidden_order_itemmeta = apply_filters(
'woocommerce_hidden_order_itemmeta',
array(
'_image',
'_qty',
'_tax_class',
'_product_id',
'_variation_id',
'_line_subtotal',
'_line_subtotal_tax',
'_line_total',
'_line_tax',
'method_id',
'cost',
'_reduced_stock',
'_restock_refunded_items',
)
);

$product_object = is_callable( array( $item, 'get_product' ) ) ? $item->get_product() : null;

$thumbnail = $product_object->get_image( array( 60, 60 ) );

// Add thumbnail
if ( $product_object->get_image_id() > 0 ) {
$html .= '<div class="item-thumbnail">' . $thumbnail . '</div>';
'image_size' => array( 50, 50 ),
}

$html .= wp_kses_post( $item->get_name() );

if ( $product_object ) {
$html .= '<div class="wc-order-item-sku">' . esc_html( $product_object->get_sku() ) . '</div>';
}

$meta_data = $item->get_formatted_meta_data( '' );

if ( $meta_data ) {
<div style="margin-bottom: 40px;">
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
<thead>
<tr>
<th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'image.', 'woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Product', 'woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Product quantity', 'woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Price', 'woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Total', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>

);
?>
</tbody>

return $html;
}
add_filter( 'woocommerce_admin_order_preview_line_item_column_new_product', 'filter_woocommerce_admin_order_preview_line_item_column_new_product', 10, 4 );

但是快速订单预览窗口中没有任何变化,谁能指出我正确的方向?

最佳答案

通过woocommerce_admin_order_preview_line_item_columns过滤钩子(Hook),我们可以选择添加一个新列,用于订单预览窗口。woocommerce_admin_order_preview_line_item_column_' . sanitize_key( $column ), '过滤钩,将变为 woocommerce_admin_order_preview_line_item_column_image因此,要在新列中显示产品缩略图,在 WooCommerce 快速订单预览窗口中,您将获得:

// Add new column
function filter_woocommerce_admin_order_preview_line_item_columns( $columns, $order ) {
// Add a new column
$new_column['image'] = __( 'Image', 'woocommerce' );

// Return new column as first
return $new_column + $columns;
}
add_filter( 'woocommerce_admin_order_preview_line_item_columns', 'filter_woocommerce_admin_order_preview_line_item_columns', 10, 2 );

function filter_woocommerce_admin_order_preview_line_item_column_image( $html, $item, $item_id, $order ) {
// Get product object
$product_object = is_callable( array( $item, 'get_product' ) ) ? $item->get_product() : null;

// Add thumbnail
if ( $product_object->get_image_id() > 0 ) {
// Get image ID
$image_id = $product_object->get_image_id();

// Get thumbnail
$thumbnail = $product_object->get_image( array( 120, 120 ) );

$html .= '<div class="item-thumbnail"><a href="' . wp_get_attachment_image_url( $image_id, 'full' ) . '" target="_blank">' . $thumbnail . '</a></div>';
}

return $html;
}
add_filter( 'woocommerce_admin_order_preview_line_item_column_image', 'filter_woocommerce_admin_order_preview_line_item_column_image', 10, 4 );

// CSS style
function add_order_notes_column_style() {
$css = '.wc-order-preview .wc-order-preview-table td, .wc-order-preview .wc-order-preview-table th { text-align: left; }';
wp_add_inline_style( 'woocommerce_admin_styles', $css );
}
add_action( 'admin_print_styles', 'add_order_notes_column_style' );
result_image

关于php - 在 WooCommerce 快速订单预览窗口的新列中显示产品缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67736059/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com