Added gift wrap checkbox to checkout page, confirmation e-mail, and order storage.
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 26 Aug 2016 16:11:30 +0000 (12:11 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 26 Aug 2016 16:11:30 +0000 (12:11 -0400)
functions.php

index 199ee00..5a2c6d5 100644 (file)
@@ -42,6 +42,16 @@ function tm_added_checkout_fields( $checkout ) {
 
     echo '</div>';
 
+    echo '<div id="tm_gift_wrap"><h3>' . __('Gift Wrap') . '</h3>';
+
+    woocommerce_form_field( 'tm_gift_wrap', array(
+        'type'          => 'checkbox',
+        'class'         => array('input-checkbox'),
+        'label'         => __('Please gift wrap.')
+        ), $checkout->get_value( 'tm_gift_wrap' ));
+
+    echo '</div>';
+
 }
 
 // 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 );