woocommerce_form_field and hidden fields

前端 未结 5 715
[愿得一人]
[愿得一人] 2021-01-14 17:18

I\'m trying to add custom fields to the WooCommerce checkout and there seems to be no output for hidden fields.

In woocommerce-template.php, hidden fie

5条回答
  •  耶瑟儿~
    2021-01-14 17:46

    If you can pull the info you need and put it into a variable you can totally bypass the need to put the info in the form. Just add the info directly to update_post_meta.

    I needed to add a value stored in a COOKIE and originally set out to add it as hidden field on the form but end up doing this instead:

    /**
     * Add the hidden referral info field to the checkout
     */
    add_action( 'woocommerce_checkout_update_order_meta', 'your_hidden_data' );
    
    function your_hidden_data( $order_id ) {
    /*
      Put your normal field saves here if needed
    */
    $cookie_name1 = $_COOKIE['ref_src']; //Get my Cookie and Assign it
    //Your hidden fields
    update_post_meta( $order_id, 'Referral_Source', $cookie_name1 );
    }
    

提交回复
热议问题