为了让WooCommerce产品图像以正确的方式"显示",我使用了uSig the wp_footer
钩子的css.这样,产品缩略图就可以正确地显示在带有margin
等的收银台上.
Code:个
add_action( 'wp_footer', 'ls_product_image_css_checkout', 900 );
function ls_product_image_css_checkout() {
// run only on checkout
if ( is_checkout() ) { ?>
<style>
.product-item-thumbnail{ float:left; padding-right:20px; }
.product-item-thumbnail img{ margin:0!important; }
</style>
<?php
}
}
现在,这是我真正的问题,是的,我已经try 了各种CSS解决方案,因为产品移除有<a class=""
,然而,无论我做什么-从 checkout 中移除产品的X
显示在缩略图的右侧,紧挨着Product Name
.
我需要把拆卸的X
放在thumbnail
的LEFT
上.
This is the code I am using:个
add_filter( 'woocommerce_cart_item_name', 'ls_product_removal_on_the_left_of_product_image_on_checkout', 20, 3 );
function ls_product_removal_on_the_left_of_product_image_on_checkout( $product_name, $cart_item, $cart_item_key ) {
// only on checkout, of course
if ( is_checkout() ) {
// get cart
$cart = WC()->cart->get_cart();
// loop through cart
foreach ( $cart as $cart_key => $cart_value ) {
if ( $cart_key == $cart_item_key ) {
$product_id = $cart_item[ 'product_id' ];
$_product = $cart_item[ 'data' ];
// this is part of what I cannot figure out
$remove_product = sprintf(
'<a class="rpfc" href="%s" title="%s" data-product_id="%s" data-product_sku="%s" data-cart_item_key="%s">✕</a>',
esc_url(wc_get_cart_remove_url( $cart_key)), __( 'Delete this product from my order', 'woocommerce' ),
esc_attr( $product_id ),
esc_attr( $_product->get_sku()),
esc_attr( $cart_item_key ));
}
}
// get product data
$product = $cart_item[ 'data' ];
// display the iamge on checkout, 40*40 px
$thumbnail = $product->get_image( array( 40, 40 ) );
// the HTML
$image_html = '<div class="product-item-thumbnail">' . $thumbnail . '</div>';
// get the product name and link it. If clicked, re-directed to the product page
$product_name_link = '<a href="' . $product->get_permalink() . '">' . $product_name . '</a>';
// the removal of the product BEFORE the image
// REMOVAL (on the left of the image) IMAGE PRODUCT NAME
$product_name = $remove_product . $image_html . $product_name_link;
}
return $product_name;
}