Created
February 6, 2018 20:52
-
-
Save EricBusch/4522ac3405597a2b10d04f2ab1043de8 to your computer and use it in GitHub Desktop.
Replace all product images in a Comparison Set that use HTTP instead of HTTPS with the default WooCommerce placeholder image. [datafeedr][dfrcs]
This file contains hidden or 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
<?php | |
/** | |
* Replace all product images in a Comparison Set that use HTTP instead of HTTPS with | |
* the default WooCommerce placeholder image. | |
* | |
* @param string $html <img> tag. | |
* @param array $p Datafeedr product array. | |
* | |
* @return string Updated $html. | |
*/ | |
function mycode_replace_http_images( $html, $p ) { | |
if ( isset( $p['image'] ) && 'https' === substr( $p['image'], 0, 5 ) ) { | |
return $html; | |
} | |
return sprintf( '<img src="%s" />', wc_placeholder_img_src() ); | |
} | |
add_filter( 'dfrcs_image', 'mycode_replace_http_images', 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment