Snippets

Visser Labs Override the imported image filename when dealing with dynamic URL's and replace the file extension

Created by Michael Visser
<?php
function custom_woo_pd_get_filename_dynamic_filename( $output, $filename ) {

    // Check we are dealing with https://images.sample-domain.com/is/image/dynamic/products/...
    if( strpos( $filename, 'images.sample-domain.com/is/image/dynamic/products' ) !== false ) {
        $output = basename( $filename );
        // Strip the filename down to the ? character
        $pos = strpos( $output, '?' );
        $output = substr( $output, 0, $pos );
    }

    // Check if the filename contains .tif and replace it with .jpg
    if( strpos( $output, '.tif' ) == false )
        $output = str_replace( '.tif', '.jpg', $output );

    return $output;

}
add_filter( 'woo_pd_get_filename_dynamic_filename', 'custom_woo_pd_get_filename_dynamic_filename', 10, 2 );
?>

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.