diff --git a/app/config/wp/woo-custom-checkout-fields.php b/app/config/wp/woo-custom-checkout-fields.php index b479a14..3269c97 100644 --- a/app/config/wp/woo-custom-checkout-fields.php +++ b/app/config/wp/woo-custom-checkout-fields.php @@ -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 '

'.__('CPF').': ' . get_post_meta( $order->get_id(), '_pdocument', true ) . '

'; + $nationality = get_user_meta($order->get_customer_id(), 'nationality'); + $pdocument_label = ($nationality == 'brazilian') ? 'CPF' : 'Passport'; + echo '

'.__($pdocument_label).': ' . get_user_meta( $order->get_customer_id(), 'pdocument', true ) . '

'; + +} +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 '

'.__('Delivery', 'base-camp').' ======

'; + echo '

'.__('Type', 'base-camp').': ' . ucfirst($delivery_type) . '

'; + + if ( $delivery_enable == 'yes' ) { + echo '

'; + echo ''.__('Arrival date', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_arrival_date', true ) . '
'; + echo ''.__('Departure date', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_departure_date', true ) . '
'; + echo '

'; + + if ( $delivery_type == 'hotel' ) { + echo '

'; + echo ''.__('Hotel Name', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_hotel_name', true ) . '
'; + echo ''.__('Reservation #', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_hotel_reservation', true ) . '
'; + echo ''.__('Customer name', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_hotel_customer_name', true ) . '
'; + echo '

'; + } + + if ( $delivery_type == 'ship' ) { + echo '

'; + echo ''.__('Ship name', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_ship_name', true ) . '
'; + echo ''.__('Cabin number', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_ship_cabin_number', true ) . '
'; + echo '

'; + } + + if ( $delivery_type == 'residence' ) { + echo '

'; + echo ''.__('Zip code', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_residence_cep', true ) . '
'; + echo ''.__('Address', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_residence_logradouro', true ) . '
'; + echo ''.__('Number', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_residence_numero', true ) . '
'; + echo ''.__('Neighborhood', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_residence_bairro', true ) . '
'; + echo ''.__('Other information', 'base-camp').': ' . get_post_meta( $order->get_id(), '_delivery_residence_complemento', true ) . '
'; + echo '

'; + } + } + } -add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 ); \ No newline at end of file +add_action( 'woocommerce_admin_order_data_after_shipping_address', 'custom_checkout_field_display_admin_order_meta_shipping', 10, 1 ); diff --git a/app/config/wp/woo-custom-functions.php b/app/config/wp/woo-custom-functions.php index ff1e33b..d29e7cd 100644 --- a/app/config/wp/woo-custom-functions.php +++ b/app/config/wp/woo-custom-functions.php @@ -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); + } } \ No newline at end of file diff --git a/app/config/wp/add-options-to-database.php b/app/config/wp/woo-save-to-database.php similarity index 84% rename from app/config/wp/add-options-to-database.php rename to app/config/wp/woo-save-to-database.php index 64a0c29..122782e 100644 --- a/app/config/wp/add-options-to-database.php +++ b/app/config/wp/woo-save-to-database.php @@ -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 ); @@ -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); \ No newline at end of file diff --git a/resources/assets/sass/woocommerce/_common.sass b/resources/assets/sass/woocommerce/_common.sass index 1ddccd1..e873824 100644 --- a/resources/assets/sass/woocommerce/_common.sass +++ b/resources/assets/sass/woocommerce/_common.sass @@ -166,5 +166,4 @@ input[name='update_cart'] .woocommerce-form-register .select - width: 100% - + width: 100% \ No newline at end of file diff --git a/woocommerce/cart/cart.php b/woocommerce/cart/cart.php index 596123c..06e1ab5 100644 --- a/woocommerce/cart/cart.php +++ b/woocommerce/cart/cart.php @@ -202,24 +202,22 @@ \ No newline at end of file diff --git a/woocommerce/order/order-details-customer.php b/woocommerce/order/order-details-customer.php index cf8e77d..b631aef 100644 --- a/woocommerce/order/order-details-customer.php +++ b/woocommerce/order/order-details-customer.php @@ -42,7 +42,7 @@

get_billing_email() ); ?>

-

CPF: get_id(), '_billing_cpf', true ); ?>

+ CPF: get_customer_id(), 'pdocument', true ); ?>

*/ ?>