Posts

Showing posts with the label thumbnails

Set Woocommerce product thumbnail with new thumbnail PHP

Image
Clash Royale CLAN TAG #URR8PPP Set Woocommerce product thumbnail with new thumbnail PHP I have created a custom plugin to import and export woocommerce products. I am facing an issue that when i try to import the CSV, the thumbnails of the products got changed and set to the old one which were added to the products earlier. I have full image URL in the CSV. Here is my import code: $product_img = $row[13]; //Product Image $res = $wpdb->get_results('select post_id from ' . $wpdb->prefix . 'postmeta where meta_value like "%' . basename($product_img). '%"'); if(count($res) == 0) { $res = $wpdb->get_results('select ID as post_id from ' . $wpdb->prefix . 'posts where guid="' . $product_img . '"'); } $thumbnail_id = $res[0]->post_id; set_post_thumbnail( $product_id, $thumbnail_id ); $attach_data = wp_generate_attachment_metadata( $thumbnail_id, $product_img ); wp_upda...

How to adjust this script to use Glob instead of 1 file

Image
Clash Royale CLAN TAG #URR8PPP How to adjust this script to use Glob instead of 1 file I have created this script based on reading other posts on StackOverflow. The script creates a thumbnail from the original image and adds it to a folder. The source images are located on my local server so Glob would work however I am not sure how to adjust this script so that it will run this function on all files in a folder (Glob). I realize it may be memory intensive but I only need to do it a few times on several folders and I'll be done with it. Just in case you are questioning the reason I have included $height2, it is a little hack I came up with where we create the thumbnail while maintaining the aspect ratio then only save the top 250px so that the thumb is 250 x 250 but not distorted (stretched). It works great. I just need to adjust to do a batch of all images in the source folder. Any help would be great. Please keep in mind that I am a front end developer (html and css) and not gre...