Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed optimised image issue with the WC cart page #826

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions inc/compatibilities/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public function should_load() {
public function register() {
if ( Optml_Main::instance()->admin->settings->use_lazyload() ) {
add_filter( 'optml_lazyload_early_flags', [ $this, 'add_lazyload_early_flag' ], PHP_INT_MAX, 1 );
if ( class_exists( '\Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils' ) && \Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils::is_cart_block_default() && function_exists( 'wc_cart_totals_subtotal_html' ) ) {
add_filter( 'image_downsize', [ $this, 'filter_cart_item_image' ], PHP_INT_MAX, 3 );
}
}
}
/**
Expand Down Expand Up @@ -77,4 +80,23 @@ public function should_load_early() {
}
return false;
}

/**
* This filter will replace all the images retrieved via "wp_get_image" type of functions.
*
* @param array $image The filtered value.
* @param int $attachment_id The related attachment id.
* @param array|string $size This could be the name of the thumbnail size or an array of custom dimensions.
*
* @return array
*/
public function filter_cart_item_image( $image, $attachment_id, $size ) {
if ( ! function_exists( 'is_cart' ) ) {
return $image;
}
if ( ! is_cart() ) {
return $image;
}
return Optml_Tag_Replacer::instance()->filter_image_downsize( $image, $attachment_id, $size );
}
}
Loading