Skip to content

Instantly share code, notes, and snippets.

@braddalton
Last active May 24, 2024 07:47
Show Gist options
  • Save braddalton/df2675d6dac3bcb23b723a907dc66345 to your computer and use it in GitHub Desktop.
Save braddalton/df2675d6dac3bcb23b723a907dc66345 to your computer and use it in GitHub Desktop.
Use woocommerce_placeholder_img_src filter hook. This is the original function containing the filter. Full Tutorial https://wpsites.net/?p=115999
function wc_placeholder_img_src( $size = 'woocommerce_thumbnail' ) {
$src = WC()->plugin_url() . '/assets/images/placeholder.png';
$placeholder_image = get_option( 'woocommerce_placeholder_image', 0 );
if ( ! empty( $placeholder_image ) ) {
if ( is_numeric( $placeholder_image ) ) {
$image = wp_get_attachment_image_src( $placeholder_image, $size );
if ( ! empty( $image[0] ) ) {
$src = $image[0];
}
} else {
$src = $placeholder_image;
}
}
return apply_filters( 'woocommerce_placeholder_img_src', $src );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment