Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function is_attachment_image($attachment_id) {
- if (!is_numeric($attachment_id) || $attachment_id <= 0) {
- return false;
- }
- $mime_type = get_post_mime_type($attachment_id);
- if ($mime_type && strpos($mime_type, 'image/') === 0) {
- return true;
- }
- return false;
- }
- add_filter('wcfm_custom_field_value', function($val, $name, $product_id, $field_type, $field) {
- if ($field_type == 'upload') {
- $attachment_id = get_post_meta($product_id, $name, true);
- // Ensure we have a valid attachment ID and it's an image
- if (is_numeric($attachment_id) && $attachment_id > 0 && is_attachment_image($attachment_id)) {
- $image_url = wp_get_attachment_url($attachment_id);
- if ($image_url) {
- $alt_text = isset($field['label']) ? esc_attr(wcfm_removeslashes(__($field['label'], 'WCfM'))) : '';
- return '<img src="' . esc_url($image_url) . '" alt="' . $alt_text . '" style="max-width:250px; height:auto;"/>';
- }
- }
- }
- return $val;
- }, 10, 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement