From: Chuck Scott Date: Fri, 26 Aug 2016 16:11:30 +0000 (-0400) Subject: Added gift wrap checkbox to checkout page, confirmation e-mail, and order storage. X-Git-Tag: v1.0.5^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=09994b02196f1d29f12e17104538cb40e303ca1a;p=WP-Themes%2Fthemoleholeonline.git Added gift wrap checkbox to checkout page, confirmation e-mail, and order storage. --- diff --git a/functions.php b/functions.php index 199ee00..5a2c6d5 100644 --- a/functions.php +++ b/functions.php @@ -42,6 +42,16 @@ function tm_added_checkout_fields( $checkout ) { echo ''; + echo '

' . __('Gift Wrap') . '

'; + + woocommerce_form_field( 'tm_gift_wrap', array( + 'type' => 'checkbox', + 'class' => array('input-checkbox'), + 'label' => __('Please gift wrap.') + ), $checkout->get_value( 'tm_gift_wrap' )); + + echo '
'; + } // Get custom field data and store it in post meta data @@ -54,12 +64,17 @@ function tm_added_checkout_fields_order_meta( $order_id ) { update_post_meta( $order_id, 'Gift Message', sanitize_text_field( $_POST['tm_gift_message'] ) ); } + if (isset($_POST['tm_gift_wrap'])) { + update_post_meta( $order_id, 'Gift Wrap', 'Yes'); + } + } // Add custom fields to order E-Mail messages add_filter('woocommerce_email_order_meta_keys', 'tm_added_checkout_fields_email'); function tm_added_checkout_fields_email( $keys ) { $keys[] = 'Gift Message'; + $keys[] = 'Gift Wrap'; return $keys; } @@ -72,14 +87,25 @@ function sb_woo_remove_reviews_tab($tabs) { // Add custom fields to order printouts function add_custom_fields_to_order_printout( $fields, $order ) { + $new_fields = array(); + if( get_post_meta( $order->id, 'Gift Message', true ) ) { $new_fields['Gift Message'] = array( 'label' => 'Gift Message', 'value' => get_post_meta( $order->id, 'Gift Message', true ) ); } + + if( get_post_meta( $order->id, 'Gift Wrap', true ) ) { + $new_fields['Gift Wrap'] = array( + 'label' => 'Gift Wrap', + 'value' => get_post_meta( $order->id, 'Gift Wrap', true ) + ); + } + return array_merge( $fields, $new_fields ); + } add_filter( 'wcdn_order_info_fields', 'add_custom_fields_to_order_printout', 10, 2 );