在结帐页面上显示产品图片和名称

时间:2019-09-18 13:56:46

标签: woocommerce checkout code-snippets

如何放置代码以同时显示产品的图片和图片?

function isa_woo_cart_attributes($cart_item, $cart_item_key) {
    global $product; 
    if (is_cart()){ 
        echo "<style>#checkout_thumbnail{display:none;}</style>"; 
    } 
    $item_data = $cart_item_key['data']; 
    $post = get_post($item_data->id); 
    $thumb = get_the_post_thumbnail($item_data->id, array( 32, 50)); 
    echo '<div id="checkout_thumbnail" style="float: left; padding-right: 8px">' . $thumb . '</div> '; 
} 
add_filter('woocommerce_cart_item_name', isa_woo_cart_attributes, 10, 2);

$product = new WC_product($item_data->id);
echo $product->name;
echo $product->price;

1 个答案:

答案 0 :(得分:1)

通过以下代码段替换您的代码-

function isa_woo_cart_attributes( $product_name, $cart_item ) {
    $_product = $cart_item['data'];
    $product_permalink = $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '';
    $thumbnail = $_product->get_image();
    printf( '<a href="%s">%s</a>%s', esc_url( $product_permalink ), $thumbnail, $product_name );
} 
add_filter('woocommerce_cart_item_name', 'isa_woo_cart_attributes', 99, 2);

代码进入活动主题的功能。php