Home Forums WoodMart support forum custom product fields conflict with the template.

custom product fields conflict with the template.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #212492

    arty
    Participant

    hi,
    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,
    Menelaos

    #212512

    Artem Temos
    Keymaster

    Hello,

    Try to change the field name from $_FILES[‘image’] to something like $_FILES[‘my_custom_image’].

    Regards

    #212540

    arty
    Participant

    hello,
    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)

    #212550

    Artem Temos
    Keymaster

    Try to disable AJAX add to cart option in Theme Settings -> Product page.

    #212565

    arty
    Participant

    it’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,
    Menelaos

    #212577

    Artem Temos
    Keymaster

    Our 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.

    #212678

    arty
    Participant

    i understand,
    could you please point me to the right direction?
    thank you

    #212679

    Artem Temos
    Keymaster

    Yes, we already described where is the conflict coming from. Sorry, but we don’t have any instructions for such customizations.

    #212761

    arty
    Participant

    could you please tell me which file is responsible so i know where to look?
    thank you in advance,
    Menelaos

    #212787

    Artem Temos
    Keymaster

    You can find the handler PHP function in the file inc/integrations/woocommerce/functions.php

Viewing 10 posts - 1 through 10 (of 10 total)