function product_imager_set_images() { // Verify the AJAX request check_ajax_referer('product_imager_nonce', 'security'); // Get product ID and image URLs from the AJAX request $product_id = isset($_POST['product_id']) ? intval($_POST['product_id']) : 0; $image_urls = isset($_POST['image_urls']) ? (array) $_POST['image_urls'] : []; // Validate the input if (empty($product_id)) { wp_send_json_error(['message' => __('Error: Product ID is missing.', 'product-imager')]); } if (empty($image_urls)) { wp_send_json_error(['message' => __('Error: No images were selected.', 'product-imager')]); } // Define the uploads directory for saving images $upload_dir = wp_upload_dir(); $product_images_dir = $upload_dir['basedir'] . '/productimages'; // Ensure the directory exists if (!file_exists($product_images_dir)) { if (!wp_mkdir_p($product_images_dir)) { wp_send_json_error(['message' => __('Error: Failed to create directory for images.', 'product-imager')]); } } $attachment_ids = []; // Process each image URL foreach ($image_urls as $image_url) { // Validate the URL if (!filter_var($image_url, FILTER_VALIDATE_URL)) { continue; // Skip invalid URLs } // Fetch the image content $image_data = wp_remote_get($image_url); if (is_wp_error($image_data)) { continue; // Skip failed downloads } $image_body = wp_remote_retrieve_body($image_data); $image_name = sanitize_file_name(basename(parse_url($image_url, PHP_URL_PATH))); $file_path = $product_images_dir . '/' . $image_name; // Save the image locally if (file_put_contents($file_path, $image_body) !== false) { // Add the image to the WordPress Media Library $attachment_id = media_handle_sideload([ 'name' => $image_name, 'tmp_name' => $file_path, ], 0); if (is_wp_error($attachment_id)) { unlink($file_path); // Clean up failed uploads continue; } // Add the attachment ID to the list $attachment_ids[] = $attachment_id; } } // Check if any images were uploaded if (empty($attachment_ids)) { wp_send_json_error(['message' => __('Error: No images were successfully uploaded.', 'product-imager')]); } // Set the first image as the featured image set_post_thumbnail($product_id, $attachment_ids[0]); // Add additional images to the product gallery if (count($attachment_ids) > 1) { update_post_meta($product_id, '_product_image_gallery', implode(',', array_slice($attachment_ids, 1))); } // Respond with success wp_send_json_success(['message' => __('Product images updated successfully!', 'product-imager')]); } Seafood – Page 4 – Horizon Foods – Wholesale Food Distributor
et-loader

Needing Assistance? Call Us: 443-402-1728
Show

J.O. Black Crab Seasoning 4-oz. Bottle

$3.41

J.O. Fish Fry 8-oz Box

$2.69

J.O. Lemon Pepper 12-oz Bottle

$8.19

J.O. Lemon Pepper 24-oz Bottle

$16.59

J.O. Lemon Pepper 4.5-oz Bottle

$3.62

Jack’s Catch Backfin Lump Crab Meat Pasteurized

$17.12

Jack’s Catch Snow Crab Meat Pasteurized

$24.90

JO #1 All Purpose Seasoning 50% LESS SALT 12/4-oz Bottles/Case

$32.21

JO #1 All Purpose Seasoning 50% LESS SALT 4-oz Bottle

$3.31

JO #1 Seafood Seasoning 12-oz Bottle

$5.69

JO #1 Seafood Seasoning 12/12-oz Bottles/Case

$62.03

JO #1 Seafood Seasoning 12/4.5-oz Bottles/Case

$26.98
Showing 48 of 108 items
Load More

We are your go to crab meat supplier!

Premium Crab Meat

ON SALE NOW

Account Menu
Account Menu
Address

704 Pulaski Hwy, Joppatowne, MD 21085

Information

Hotline: 443-402-1728
jennifer@horizonfoodstore.com

Follow Us

Cart