Reputation: 197
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;
}
Upvotes: 0
Views: 1503
Reputation: 197
I have finally found what I've been looking for on this guide: https://wisdmlabs.com/blog/add-custom-data-woocommerce-order/
Upvotes: 1