Created
September 11, 2016 16:46
-
-
Save ossvn/6fbd6fd07ef828d349814c530e8a51ab to your computer and use it in GitHub Desktop.
Dynamic WooCommerce Checkout Custom Field - It will dynamic create field for each product in cart. It's great to use in specific selection for each product in cart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_before_order_notes', 'music_select' ); | |
function music_select($checkout) { | |
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
$product_id = $cart_item['product_id']; | |
$product_name = $cart_item['data']->post->post_title; | |
woocommerce_form_field( 'music_select_'.$product_id, array( | |
'type' => 'select', | |
'class' => array('my-field-class form-row-wide '.$product_id), | |
'label' => __('Please select music for '.$product_name. ' video'), | |
'placeholder' => __('Enter something'), | |
'options' => array('track_1' => 'Track 1'), | |
), | |
$checkout->get_value( 'music_select' )); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment