Created
July 20, 2020 12:55
-
-
Save sarangs07/7d232cd4b7cbc0b7f8f3b5f854598211 to your computer and use it in GitHub Desktop.
Display product image in the order review section.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* How to add the custome code. | |
* | |
* Please follow below instructions: | |
* 1. Copy the below code. | |
* 2. Open your child theme's functions.php file. | |
* 3. Paste the copied code at the very bottom of it & save the file OR upload it on your server/hosting. | |
*/ | |
/** | |
* Display product image in the order review section. | |
* | |
* @param string $name Product Name. | |
* @param array $cart_item Cart Data. | |
* @return string $cart_item_key cart item key. | |
*/ | |
function product_image_on_checkout( $name, $cart_item, $cart_item_key ) { | |
// Return if not checkout page. | |
if ( ! is_checkout() ) { | |
return $name; | |
} | |
// Get product object. | |
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); | |
// Get product thumbnail. | |
$thumbnail = $_product->get_image(); | |
// Add wrapper to image and add some css. | |
$image = '<div class="ts-product-image" style="width: 52px; height: 45px; display: inline-block; padding-right: 7px; vertical-align: middle;">' | |
. $thumbnail . | |
'</div>'; | |
// Prepend image to name and retun it. | |
return $image . $name; | |
} | |
add_filter( 'woocommerce_cart_item_name', 'product_image_on_checkout', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment