简体   繁体   中英

WooCommerce Add New Form Field On Product Page

I've driven myself crazy looking for this all over the internet on how I would go around sorting this.

So I need to add a new form below the variations on WooCommerce, and get this to post through to the checkout and then into the order notes once payment has been processed. I have got the select fields added to the product view page (front end) using the code below, but now I need to somehow get this to post to the basket and checkout and then into the order in the backend, but not sure where to start with a function doing this.

add_action( 'woocommerce_before_add_to_cart_button', 'espresso_add_flavour_field', 0 );
function espresso_add_flavour_field() {
    global $post;
    global $product;

    // Show this only on the subscription boxes
    $product_type = $product->get_type();
    if( $product_type == 'variable-subscription' ){
        echo "<div class='pick-flavor'>";
        //echo get_post_meta( $post->ID, 'Product Code', true );
        echo "Please select your favorite flavors we can include in your subscription box*<br>";

        $flavors = ( get_terms('pa_do-not-use-sub-flav', array('hide_empty' => false) ) );
        echo '<select name="_redeem_in_stores[]" class="chosen-select" multiple="multiple">';
        foreach($flavors as $flavor){
            echo '<option>' . $flavor->name . '</option>';
        }
        echo "</select>";

        echo "</div>";
    }

    return true;
}

我终于找到了我在本指南中一直在寻找的东西: https : //wisdmlabs.com/blog/add-custom-data-woocommerce-order/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM