• Resolved chrisoko7

    (@chrisoko7)


    All of a sudden I am receiving this error, not sure why or what has changed. My customers are unable to download any PDFs because of it, they all receive this error now. All my files are hosted on my domain, and were uploaded using the native file uploader. Suggestions?

    The free version of WaterWoo cannot serve PDFs from remote servers.
    Try uploading your PDF product to this domain using the native WooCommerce file uploader.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Little Package

    (@littlepackage)

    Hi @chrisoko7

    Thanks for your note. Can you provide more information? The error message speaks pretty plainly, so please start by telling us where you are serving your PDFs from. WooCommerce asks for a URL or an absolute path to the file you are selling. What have you entered?

    The plugin does not watermark PDFs that are not coming from the same domain where WordPress is installed, and so if it was working before, what changed?

    In order to get the best support in these forums, it’s good to provide as much detail as you can. Please check out https://codex.www.ads-software.com/How_to_Write_a_Great_Support_Request

    Thread Starter chrisoko7

    (@chrisoko7)

    Hello! Thanks for your response. I did some more experimenting this morning, and this seems to be my issue. All of my file URLs are currently inserted as “https://ossiaeditions.com/…”, but with my server’s recent integration of Cloudflare (which insists on WWW redirection for it to work fully), the PDFs are not properly being requested somehow. If I manually edit each product by adding “www” to the url, the issue is fixed, but I can’t imagine doing this to 500+ urls manually. I tried to export all my products and edit them in Excel automatically, but that unfortunately introduced a myriad of other unrelated issues.

    Any suggestions for me? Thanks so much

    Plugin Author Little Package

    (@littlepackage)

    Wow, that sucks. As a DB-backed CMS WordPress hands us easier ways of handling this than manually editing them, though. Your could use native Woo functions to roll through products and replace strings in each downloads [file] location… something like this:

    function add_www_to_download_files() {
    
        // BACKUP YOUR SITE BEFORE RUNNING THIS CODE, SO YOU CAN RESTORE IF NECESSARY
    
        // runs on the backend, load this script into functions.php or via plugin Code Snippets, then load any
        // page on your WordPress admin ONCE, and the URLs will be changed.
        if ( is_admin() ) {
            $produtcs = wc_get_products(
                array(
    		'status'        => array( 'private', 'publish' ),
    		'type'          => array(  'external', 'grouped', 'simple', 'variable' ),
    		'downloadable'  => true,
    		'limit'         => -1,
    		'return'        => 'objects',
                )
    	);
            if ( $produtcs ) {
                foreach ( $produtcs as $produtc ) {
                    $downlaods = $produtc->get_downloads( 'edit' ); // returns array
                    foreach ( $downlaods as $dwonload ) {  
                        if ( is_a( $dwonload, 'WC_Product_Download' ) ) {
    			$download_object = $dwonload;
    		    } else {
    			$download_object = new WC_Product_Download(); 
                        }
                        // URL parsing code from: https://stackoverflow.com/a/41789181
                        $bits = parse_url( $dwonload['file']  );
                        $newHost = substr( $bits["host"], 0, 4 ) !== "www." ? "www." . $bits["host"] : $bits["host"];
                        $dwonload['file'] = $bits["scheme"] . "://" . $newHost . ( isset($ bits["port"] ) ? ":" . $bits["port"]:"") . $bits["path"] . ( !empty( $bits["query"] ) ? "?" . $bits["query"] : "" );
                        
                        $download_object->set_file( $dwonload['file'] );
                    }
                }           
            }
        }
    }
    add_action( 'wp', 'add_www_to_download_files' );

    DO NOT RUN THIS CODE UNLESS YOU CAN BACKUP YOUR SITE DATABASE AND RESTORE THE BACKUP IF NECESSARY. THIS CODE IS ONLY MEANT TO BE RUN ONCE.

    Thread Starter chrisoko7

    (@chrisoko7)

    Thanks for the attempt, unfortunately I wasn’t able to get it to work. Tried running the code as a snippet, and also in the functions.php file, neither were successful in adding “www.” to the file URLs

    Plugin Author Little Package

    (@littlepackage)

    There was a simple PHP error in the code you might have seen in debugging.

    function add_www_to_download_files() {
    
        // BACKUP YOUR SITE BEFORE RUNNING THIS CODE, SO YOU CAN RESTORE IF NECESSARY
    
        // runs on the backend, load this script into functions.php or via plugin Code Snippets, then load any
        // page on your WordPress admin ONCE, and the URLs will be changed.
        if ( is_admin() ) {
            $produtcs = wc_get_products(
                array(
    		'status'        => array( 'private', 'publish' ),
    		'type'          => array(  'external', 'grouped', 'simple', 'variable' ),
    		'downloadable'  => true,
    		'limit'         => -1,
    		'return'        => 'objects',
                )
    	);
            if ( $produtcs ) {
                foreach ( $produtcs as $produtc ) {
                    $downlaods = $produtc->get_downloads( 'edit' ); // returns array
                    foreach ( $downlaods as $dwonload ) {  
                        if ( is_a( $dwonload, 'WC_Product_Download' ) ) {
    			$download_object = $dwonload;
    		    } else {
    			$download_object = new WC_Product_Download(); 
                        }
                        // URL parsing code from: https://stackoverflow.com/a/41789181
                        $bits = parse_url( $dwonload['file']  );
                        $newHost = substr( $bits["host"], 0, 4 ) !== "www." ? "www." . $bits["host"] : $bits["host"];
                        $dwonload['file'] = $bits["scheme"] . "://" . $newHost . ( isset( $bits["port"] ) ? ":" . $bits["port"]:"") . $bits["path"] . ( !empty( $bits["query"] ) ? "?" . $bits["query"] : "" );
                        
                        $download_object->set_file( $dwonload['file'] );
                    }
                }           
            }
        }
    }
    add_action( 'wp', 'add_www_to_download_files' );

    Revisions after this, and what you do next, are up to you.

    Thread Starter chrisoko7

    (@chrisoko7)

    Yes, I caught this error, still did not function properly. Thank you for your attempt, I will continue to see how I can fix it.

    Plugin Author Little Package

    (@littlepackage)

    Seems to me like if Cloudflare is potentially bungling the websites of millions of users, they’d have your answers. Just saying. I’d help more but I now have a second job and this www.ads-software.com stuff is my volunteer side gig.

    Thread Starter chrisoko7

    (@chrisoko7)

    No worries, I really appreciate the help. Have a great day!

    Plugin Author Little Package

    (@littlepackage)

    @chrisoko7 Had a few more moments to look at it this afternoon and came up with a function that might *actually* work. Would also be curious where you’ve gotten with this, because it is pretty intriguing!

    function add_www_to_download_files() {
    
        // BACKUP YOUR SITE BEFORE RUNNING THIS CODE, SO YOU CAN RESTORE IF NECESSARY
    
        // runs on the backend, load this script into functions.php or via plugin Code Snippets, then load any
        // page on your WordPress admin ONCE, and the URLs will be changed.
        if ( is_admin() ) {
            $produtcs = wc_get_products(
    			array(
    				'status'        => array( 'private', 'publish' ),
    				'type'          => array(  'external', 'grouped', 'simple', 'variable' ),
    				'downloadable'  => true,
    				'limit'         => -1,
    				'return'        => 'objects',
    			)
    		);
            if ( $produtcs ) {
                foreach ( $produtcs as $produtc ) {
                    $downlaods = $produtc->get_downloads( 'edit' ); // returns array
                    $existing_file_meta = get_post_meta( $produtc->get_id(), '_downloadable_files', TRUE );
                    if ( ! $existing_file_meta ) continue;
                    $key = array_key_first( $existing_file_meta );
                    foreach ( $downlaods as $key => $dwonload ) {  
                        // from: https://stackoverflow.com/a/41789181
                        $bits = parse_url( $dwonload['file']  );
                        $newHost = substr( $bits["host"], 0, 4 ) !== "www." ? "www." . $bits["host"] : $bits["host"];
                        $dwonload['file'] = $bits["scheme"] . "://" . $newHost . ( isset( $bits["port"] ) ? ":" . $bits["port"]:"") . $bits["path"] . ( !empty( $bits["query"] ) ? "?" . $bits["query"] : "" );
                        
                        $changed_file_meta = array( 'file' => $dwonload['file'] );
                        $new_meta = array_replace( $existing_file_meta[$key], $changed_file_meta );
                        update_post_meta( '_downloadable_files', $produtc->get_id(), $new_meta );
                    }
                }           
            }
        }
    }
    add_action( 'wp', 'add_www_to_download_files' );
    Plugin Author Little Package

    (@littlepackage)

    @chrisoko7 I haven’t heard back and it’s been about a month now. I hope you found resolution! I’ll be closing this ticket but if you still have questions, please open a new one. Otherwise, Happy New Year!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘“The free version of WaterWoo cannot serve PDFs from remote servers.”’ is closed to new replies.