Skip to content

Instantly share code, notes, and snippets.

@EricBusch
Created February 6, 2018 20:52
Show Gist options
  • Save EricBusch/4522ac3405597a2b10d04f2ab1043de8 to your computer and use it in GitHub Desktop.
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]
<?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