Support

Account

Home Forums General Issues acf field hooking up with woocommerce hook

Solving

acf field hooking up with woocommerce hook

  • im trying to display acf field in woocommerce product-data -> general tab
    woocomerce hook

    
    add_action('woocommerce_product_options_general_product_data', 'add_custom_file_upload');
    function add_custom_file_upload() {
    if( function_exists('acf_add_local_field_group') ):
    
    acf_add_local_field_group(array (
        'key' => 'group_12uyy',
        'title' => 'My Group 123',
        'fields' => array (
            array (
                'key' => 'field_1',
                'label' => 'Sub Title light',
                'name' => 'sub_title_light',
                'type' => 'file',
                'prefix' => '',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => array (
                    'width' => '',
                    'class' => '',
                    'id' => '',
                ),
                'default_value' => '',
                'placeholder' => '',
                'prepend' => '',
                'append' => '',
                'maxlength' => '',
                'readonly' => 0,
                'disabled' => 0,
            )
        ),
        'location' => array (
            array (
                array (
                    'param' => 'post_type',
                    'operator' => '==',
                    'value' => 'product',
                ),
            ),
        ),
        'menu_order' => 0,
        'position' => 'normal',
        'style' => 'default',
        'label_placement' => 'top',
        'instruction_placement' => 'label',
        'hide_on_screen' => '',
    ));
    
    endif;
    }
    

    but when im trying to hookup acf field with woocommerce_product_options_general_product_data, its not displaying

  • iam able to insert acf field into product-data -> genreal tab

    // Add ACF file type field to WooCommerce product general settings
    function add_acf_file_field_to_woocommerce_product_options() {
        global $product_object; // Get the product object
        
        // Define the field settings
        $field_settings = array(
            'key' => 'field_my_file_field',
            'label' => 'File Field',
            'name' => 'my_file_field',
            'type' => 'file',
            'instructions' => 'Upload a file',
            'return_format' => 'url', // Change this to 'array' if you want more information about the file
    
    		'location' => array(
    		array(
    			array(
    				'param' => 'post_type',
    				'operator' => '==',
    				'value' => 'product',
    			),
    		),
    	),
        );
    
        // Render the ACF field
        acf_render_field_wrap($field_settings);
    }
    
    // Hook into WooCommerce product general options
    add_action('woocommerce_product_options_general_product_data', 'add_acf_file_field_to_woocommerce_product_options');

    but upload file is not saved……. when i update the page uploaded file is gone…..
    why my upload file is not saved

  • trying to save the field data of upload file but failed

    / Add ACF file type field to WooCommerce product general settings
    function add_acf_file_field_to_woocommerce_product_options() {
        global $product_object; // Get the product object
        $product_id = $product_object->get_id(); // Get the product ID
        // Define the field settings
        $field_settings = array(
            'key' => 'field_my_file_field',
            'label' => 'File Field',
            'name' => 'my_file_field',
            'type' => 'file',
            'instructions' => 'Upload a file',
            'return_format' => 'url', // Change this to 'array' if you want more information about the file
    
    		<!-- 'location' => array(
    		array(
    			array(
    				'param' => 'post_type',
    				'operator' => '==',
    				'value' => 'product',
    			),
    		),
    	    ), -->
        );
    
        // Render the ACF field
        acf_render_field_wrap($field_settings);
    
        if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['woocommerce_process_product_meta'])) {
            $file_field_value = $_POST['acf']['my_file_field'];
            
            // Update the ACF field value
            update_field('field_my_file_field', $file_field_value, $product_id);
        }
    }
    
    // Hook into WooCommerce product general options
    add_action('woocommerce_product_options_general_product_data', 'add_acf_file_field_to_woocommerce_product_options');

    even this menthod is unable save the upload file data

  • There is only one way to add fields into the WC interface in that location. This is to use acf_form(). You set the “form” argument to false.

    ACF is not capable of adding fields to that location.

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

You must be logged in to reply to this topic.