Support

Account

Home Forums General Issues acf field hooking up with woocommerce hook Reply To: acf field hooking up with woocommerce hook

  • 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