Skip to content

Commit

Permalink
Finishing saving delivery data to database and showing at the admin o…
Browse files Browse the repository at this point in the history
…rder edit page
  • Loading branch information
Michel Moraes committed Oct 26, 2018
1 parent bc1981c commit 4a78835
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 30 deletions.
54 changes: 52 additions & 2 deletions app/config/wp/woo-custom-checkout-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,56 @@ function custom_override_checkout_fields( $fields ) {
* Display field value on the order edit page
*/
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('CPF').':</strong> ' . get_post_meta( $order->get_id(), '_pdocument', true ) . '</p>';
$nationality = get_user_meta($order->get_customer_id(), 'nationality');
$pdocument_label = ($nationality == 'brazilian') ? 'CPF' : 'Passport';
echo '<p><strong>'.__($pdocument_label).':</strong> ' . get_user_meta( $order->get_customer_id(), 'pdocument', true ) . '</p>';

}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );

function action_woocommerce_admin_order_data_after_shipping_address() {

}
remove_action('woocommerce_admin_order_data_after_shipping_address', 'action_woocommerce_admin_order_data_after_shipping_address', 10, 3 );

function custom_checkout_field_display_admin_order_meta_shipping($order) {
$delivery_enable = get_post_meta( $order->get_id(), '_delivery_enabled', true );
$delivery_type = get_post_meta( $order->get_id(), '_delivery_type', true );

echo '<h3>'.__('Delivery', 'base-camp').' ====== </h3>';
echo '<p><strong>'.__('Type', 'base-camp').':</strong> ' . ucfirst($delivery_type) . '</p>';

if ( $delivery_enable == 'yes' ) {
echo '<p>';
echo '<strong>'.__('Arrival date', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_arrival_date', true ) . '<br />';
echo '<strong>'.__('Departure date', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_departure_date', true ) . '<br />';
echo '</p>';

if ( $delivery_type == 'hotel' ) {
echo '<p>';
echo '<strong>'.__('Hotel Name', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_hotel_name', true ) . '<br />';
echo '<strong>'.__('Reservation #', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_hotel_reservation', true ) . '<br />';
echo '<strong>'.__('Customer name', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_hotel_customer_name', true ) . '<br />';
echo '</p>';
}

if ( $delivery_type == 'ship' ) {
echo '<p>';
echo '<strong>'.__('Ship name', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_ship_name', true ) . '<br />';
echo '<strong>'.__('Cabin number', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_ship_cabin_number', true ) . '<br />';
echo '</p>';
}

if ( $delivery_type == 'residence' ) {
echo '<p>';
echo '<strong>'.__('Zip code', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_residence_cep', true ) . '<br />';
echo '<strong>'.__('Address', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_residence_logradouro', true ) . '<br />';
echo '<strong>'.__('Number', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_residence_numero', true ) . '<br />';
echo '<strong>'.__('Neighborhood', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_residence_bairro', true ) . '<br />';
echo '<strong>'.__('Other information', 'base-camp').':</strong> ' . get_post_meta( $order->get_id(), '_delivery_residence_complemento', true ) . '<br />';
echo '</p>';
}
}

}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'custom_checkout_field_display_admin_order_meta_shipping', 10, 1 );
7 changes: 4 additions & 3 deletions app/config/wp/woo-custom-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ function woocommerce_custom_redirections() {
wp_redirect( get_permalink( get_option('woocommerce_checkout_page_id') ) );
}



add_action( 'woocommerce_checkout_create_order_line_item', 'wdm_add_custom_order_line_item_meta',10,4 );

function wdm_add_custom_order_line_item_meta($item, $cart_item_key, $values, $order) {
$item->add_meta_data('_many_test', 'test');
$prods_acf = get_fields($values['product_id']);
foreach ($prods_acf as $acf_key => $prod_acf) {
$item->add_meta_data($acf_key, $prod_acf->name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ function my_save_options() {
*/
function before_checkout_create_order( $order, $data ) {

$custom_delivery = WC()->session->get('delivery_enabled');
$delivery_enabled = WC()->session->get('delivery_enabled');

if ( !empty($custom_delivery) && $custom_delivery == 'yes' ) :
if ( !empty($delivery_enabled) && $delivery_enabled == 'yes' ) :
$order->update_meta_data( '_delivery_enabled', $delivery_enabled );

$delivery_type = WC()->session->get('delivery_type');
$delivery_arrival_date = WC()->session->get('delivery_arrival_date');
$delivery_departure_date = WC()->session->get('delivery_departure_date');
$delivery_departure_date = WC()->session->get('delivery_departure_date');

if ( !empty($delivery_type) )
$order->update_meta_data( '_delivery_type', $delivery_type );

Expand All @@ -53,8 +55,10 @@ function before_checkout_create_order( $order, $data ) {
}
endif;

if ( !empty($custom_delivery) && $custom_delivery == 'no' )
if ( !empty($delivery_enabled) && $delivery_enabled == 'no' ) {
$order->update_meta_data( '_delivery_enabled', $delivery_enabled );
$order->update_meta_data( '_delivery_type', 'pickup' );
}

}
add_action('woocommerce_checkout_create_order', 'before_checkout_create_order', 20, 2);
3 changes: 1 addition & 2 deletions resources/assets/sass/woocommerce/_common.sass
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,4 @@ input[name='update_cart']

.woocommerce-form-register
.select
width: 100%

width: 100%
83 changes: 66 additions & 17 deletions woocommerce/cart/cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,45 +202,43 @@
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Delivery </p>
<p class="modal-card-title"><?php _e('Delivery', 'base-camp'); ?></p>
<button class="delete" aria-label="close" v-on:click="closeDeliveryModal()"></button>
</header>

<section class="modal-card-body">
<h2 class="title is-5 modal-delivery__title">Place of stay</h2>
<h2 class="title is-5 modal-delivery__title"><?php _e('Place of stay', 'base-camp'); ?></h2>

<div class="field">
<label class="label">Location type</label>
<label class="label"><?php _e('Location type', 'base-camp'); ?></label>
<div class="control">
<div class="select">
<select v-model="modalDelivery.type">
<option><?php _e('Select', 'base-camp'); ?></option>
<option value="hotel"><?php _e('Hotel', 'base-camp'); ?></option>
<!-- <option value="residence">Residence</option> -->
<option value="ship"><?php _e('Ship', 'base-camp'); ?></option>
<option value="residence"><?php _e('Residence', 'base-camp'); ?></option>
<!-- <option value="other">Other</option> -->
</select>
</div>
</div>
</div>

<br>

<h2 class="title is-5 modal-delivery__title">Staying period</h2>
<h2 class="title is-5 modal-delivery__title"><?php _e('Staying period', 'base-camp'); ?></h2>

<div class="columns">
<div class="column">
<div class="field">
<label class="label">Arrival Date</label>
<label class="label"><?php _e('Arrival Date', 'base-camp'); ?></label>
<div class="control">
<datepicker :language="lang.br" input-class="input" v-model="modalDelivery.arrival_date"></datepicker>
</div>
</div>
</div>
<div class="column">
<div class="field">
<label class="label">Departure Date</label>
<label class="label"><?php _e('Departure Date', 'base-camp'); ?></label>
<div class="control">
<datepicker :language="lang.br" input-class="input" v-model="modalDelivery.departure_date"></datepicker>
</div>
Expand All @@ -252,12 +250,12 @@

<!-- Hotel -->
<div v-if="modalDelivery.type == 'hotel'">
<h2 class="title is-5 modal-delivery__title">Hotel</h2>
<h2 class="title is-5 modal-delivery__title"><?php _e('Hotel', 'base-camp'); ?></h2>

<div class="field">
<div class="control">
<div class="field">
<label class="label">Hotel Name</label>
<label class="label"><?php _e('Hotel Name', 'base-camp'); ?></label>
<div class="select">
<select v-model="modalDelivery.hotel.hotel_name">
<option>Select</option>
Expand All @@ -273,7 +271,7 @@
<div class="column field">
<div class="control">
<div class="field">
<label class="label">Reservation #</label>
<label class="label"><?php _e('Reservation #', 'base-camp'); ?></label>
<input type="text" class="input" v-model="modalDelivery.hotel.hotel_reservation">
</div>
</div>
Expand All @@ -282,7 +280,7 @@
<div class="column field">
<div class="control">
<div class="field">
<label class="label">Customer name</label>
<label class="label"><?php _e('Customer name', 'base-camp'); ?></label>
<input type="text" class="input" v-model="modalDelivery.hotel.hotel_customer_name">
</div>
</div>
Expand All @@ -293,13 +291,13 @@

<!-- Ship -->
<div v-if="modalDelivery.type == 'ship'">
<h2 class="title is-5 modal-delivery__title">Ship</h2>
<h2 class="title is-5 modal-delivery__title"><?php _e('Ship', 'base-camp'); ?></h2>

<div class="columns">
<div class="column field">
<div class="control">
<div class="field">
<label class="label">Ship name</label>
<label class="label"><?php _e('Ship name', 'base-camp'); ?></label>
<input type="text" class="input" v-model="modalDelivery.ship.ship_name">
</div>
</div>
Expand All @@ -308,7 +306,7 @@
<div class="column field">
<div class="control">
<div class="field">
<label class="label">Cabin number</label>
<label class="label"><?php _e('Cabin number', 'base-camp'); ?></label>
<input type="text" class="input" v-model="modalDelivery.ship.ship_cabin_number">
</div>
</div>
Expand All @@ -317,10 +315,61 @@

</div>

<!-- Residence -->
<div v-if="modalDelivery.type == 'residence'">
<h2 class="title is-5 modal-delivery__title"><?php _e('Residence', 'base-camp'); ?></h2>

<div class="columns">
<div class="column is-one-third control">
<div class="field">
<label class="label"><?php _e('Zip code', 'base-camp'); ?></label>
<input type="text" class="input" v-model="modalDelivery.residence.residence_cep">
</div>
</div>

<div class="column control">
<div class="field">
<label class="label"><?php _e('Address', 'base-camp'); ?></label>
<input type="text" class="input" v-model="modalDelivery.residence.residence_logradouro">
</div>
</div>
</div>

<div class="columns">
<div class="column is-one-fifth">
<div class="control">
<div class="field">
<label class="label"><?php _e('Number', 'base-camp'); ?></label>
<input type="text" class="input" v-model="modalDelivery.residence.residence_numero">
</div>
</div>
</div>

<div class="column">
<div class="control">
<div class="field">
<label class="label"><?php _e('Neighborhood', 'base-camp'); ?></label>
<input type="text" class="input" v-model="modalDelivery.residence.residence_bairro">
</div>
</div>
</div>

<div class="column">
<div class="control">
<div class="field">
<label class="label"><?php _e('Other information', 'base-camp'); ?></label>
<input type="text" class="input" v-model="modalDelivery.residence.residence_complemento">
</div>
</div>
</div>
</div>

</div>

</section>
<footer class="modal-card-foot">
<button class="button is-danger" v-on:click="closeDeliveryModal()">Remove Delivery</button>
<button class="button is-success" v-on:click="closeDeliveryModal('save')">Save Delivery</button>
<button class="button is-danger" v-on:click="closeDeliveryModal()"><?php _e('Remove Delivery', 'base-camp'); ?></button>
<button class="button is-success" v-on:click="closeDeliveryModal('save')"><?php _e('Save Delivery', 'base-camp'); ?></button>
</footer>
</div>
</div>
2 changes: 1 addition & 1 deletion woocommerce/order/order-details-customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<p class="woocommerce-customer-details--email"><?php echo esc_html( $order->get_billing_email() ); ?></p>
<?php endif; ?>

<p>CPF: <?php echo get_post_meta( $order->get_id(), '_billing_cpf', true ); ?></p>
<?php /* <p>CPF: <?php echo get_user_meta( $order->get_customer_id(), 'pdocument', true ); ?></p> */ ?>
</address>

<?php if ( $show_shipping ) : ?>
Expand Down

0 comments on commit 4a78835

Please sign in to comment.