Skip to content

Instantly share code, notes, and snippets.

@jaworowicz
Last active February 20, 2017 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaworowicz/549f3f96809596a6a3d23584167b67d8 to your computer and use it in GitHub Desktop.
Save jaworowicz/549f3f96809596a6a3d23584167b67d8 to your computer and use it in GitHub Desktop.
<?php
// Wstaw do Functions lub wtyczki funkcyjnej usuwając <?php i koniec kodu php ? > z konca pliku
add_action( 'woocommerce_after_order_notes', 'jcz_uczestnicy_woocommerce' );
function jcz_uczestnicy_woocommerce( $checkout ) {
global $woocommerce;
$class_basket_count = $woocommerce->cart->cart_contents_count;
$class_basket_count = $class_basket_count - 0;
if($class_basket_count >= 0){
echo '<div id="jcz_uczestnicy_woocommerce"><h3>' . __('Lista Uczestników') . '</h3>';
for ($i=1; $i <= $class_basket_count; $i++ ){
woocommerce_form_field( 'guest-name-'.$i, array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Imię Nazwisko uczestnika'),
'placeholder' => __('Wpisz imię i nazwisko'),
), $checkout->get_value( 'guest-name-'.$i ));
woocommerce_form_field( 'guest-email-'.$i, array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('E-mail gościa'),
'placeholder' => __('Wpisz e-mail'),
), $checkout->get_value( 'guest-email-'.$i ));
}
echo '</div>';
}
}
add_action( 'woocommerce_checkout_update_order_meta', 'jcz_uczestnicy_woocommerce_update_order_meta' );
function jcz_uczestnicy_woocommerce_update_order_meta( $order_id ) {
global $woocommerce;
$class_basket_count = $woocommerce->cart->cart_contents_count;
for ($i=1; $i <= $class_basket_count; $i++ ){
if ( ! empty( $_POST['guest-name-'.$i] ) ) {
update_post_meta( $order_id, 'guest-name-'.$i, sanitize_text_field( $_POST['guest-name-'.$i] ) );
update_post_meta( $order_id, 'guest-email-'.$i, sanitize_text_field( $_POST['guest-email-'.$i] ) );
}
}
}
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'jcz_uczestnicy_woocommerce_display_admin_order_meta', 10, 1 );
function jcz_uczestnicy_woocommerce_display_admin_order_meta($order){
$totla_class_ordered = $order->get_item_count();
echo '<h4>Lista uczestników</h4>';
echo '<div class="uczestnicy-woo-jcz"><table>';
echo '<thead><tr><th>Imię i Nazwisko</th><th>E-Mail uczestnika</th></tr></thead>';
for ($i=1; $i <= $totla_class_ordered; $i++ ){
echo '<tr><td>'.get_post_meta( $order->id, 'guest-name-'.$i, true ) . '</td><td>'.get_post_meta( $order->id, 'guest-email-'.$i, true ) . '</td>';
}
echo '</table></div>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment