Home › Forums › WoodMart support forum › custom product fields conflict with the template.
custom product fields conflict with the template.
- This topic has 9 replies, 2 voices, and was last updated 4 years, 6 months ago by Artem Temos.
-
AuthorPosts
-
July 20, 2020 at 7:23 am #212492
artyParticipanthi,
i have created a custom plugin which adds some custom fields in single-product page in the frontend.
all of the fields work except one.
This is the field where the user adds an image through <input type=”file”>
I have been trying to fix it for days and today i’ve tried the code with wordpress default theme and it works.
I guess there’s an incompatibility somewhere with woodmart.
i add the custom field like:add_action( 'woocommerce_before_add_to_cart_button', 'display_custom_fields' ); function display_custom_fields() { ?> <p class="form-row validate-required" id="image" > <span class="woocommerce-input-wrapper"> <label for="image" class=""><?php echo $stamp_welcome_text; ?> </label> <input type="file" name="image" accept="image/*" > </span> </p> <?php }
then i add it in the cart like:
add_filter( 'woocommerce_add_cart_item_data', 'add_cart_item_data', 10,3 ); function add_cart_item_data( $cart_item_data, $product_id ) { if ($_FILES['image'] ) { require_once( ABSPATH . 'wp-admin/includes/image.php' ); require_once( ABSPATH . 'wp-admin/includes/file.php' ); require_once( ABSPATH . 'wp-admin/includes/media.php' ); $attachment_id = media_handle_upload( 'image', 0 ); if ( is_wp_error( $attachment_id ) AND $_FILES['image']['size'] > 0) { die($attachment_id->get_error_message().'. Παρακαλώ επικοινωνήστε μαζί μας.'); } else $cart_item_data['image'] = $attachment_id; } return $item_cart_data; }
Unfortunately and for a totally wierd reason to me $_FILES[‘image’] is NOT set
although with twentyywenty and storefront themes it’s working perfectly.
Your help is highly appreciated
thank you in advance,
MenelaosJuly 20, 2020 at 8:02 am #212512
Artem TemosKeymasterHello,
Try to change the field name from
$_FILES[‘image’]
to something like$_FILES[‘my_custom_image’]
.Regards
July 20, 2020 at 8:43 am #212540
artyParticipanthello,
i have already tried that and it’s producing the same results.
yes, i have changed all regarding entris(in both parts of the code)July 20, 2020 at 8:55 am #212550
Artem TemosKeymasterTry to disable AJAX add to cart option in Theme Settings -> Product page.
July 20, 2020 at 9:06 am #212565
artyParticipantit’s working without AJAX.
however AJAX is an option that my client woule like to keep.
Could you please point me to the right direction in order to keep AJAX working and have the custom field as well?
thank you in advance,
MenelaosJuly 20, 2020 at 9:24 am #212577
Artem TemosKeymasterOur custom AJAX handler is not designed for image fields. If you want to keep it, you will need to customize its code also but we don’t have an instruction for this.
July 20, 2020 at 1:37 pm #212678
artyParticipanti understand,
could you please point me to the right direction?
thank youJuly 20, 2020 at 7:38 pm #212679
Artem TemosKeymasterYes, we already described where is the conflict coming from. Sorry, but we don’t have any instructions for such customizations.
July 20, 2020 at 8:57 pm #212761
artyParticipantcould you please tell me which file is responsible so i know where to look?
thank you in advance,
MenelaosJuly 21, 2020 at 6:12 am #212787
Artem TemosKeymasterYou can find the handler PHP function in the file
inc/integrations/woocommerce/functions.php
-
AuthorPosts
- You must be logged in to create new topics. Login / Register