adding query string parameters for the enquire form
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 24 Jun 2016 15:52:36 +0000 (11:52 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 24 Jun 2016 15:52:36 +0000 (11:52 -0400)
functions.php
sidebar.php

index f4a8ed9..80ea695 100644 (file)
@@ -112,16 +112,41 @@ function woo_photos_content() {
 
 add_filter( 'gform_field_value_product_name', 'gform_add_product_name_field' );
 function gform_add_product_name_field( $value ) {
-//    global $product;
-//    return $product->get_title();
+    
+    global $product, $post, $woocommerce;
+    
+    if ( ! empty($_GET) && isset($_GET)){
+        $title = $_GET['title'];
+    } else {
+        $id = $post->ID;
+        $product_meta = new WC_Product($id);
+        $title = $product_meta->get_title();
+    }
+
+    if ($title){
+        return $title;
+    } else {
+        return  __( '(not set)', 'woocommerce' );
+    }
 }
 add_filter( 'gform_field_value_product_sku', 'gform_add_product_sku_field' );
 function gform_add_product_sku_field( $value ) {
-//    global $product;
-//    return ( $sku = $product->get_sku() ) ? $sku : __( '(not set)', 'woocommerce' );
-}
-
+    global $product, $post, $woocommerce;
+    
+    if ( ! empty($_GET) && isset($_GET)){
+        $sku = $_GET['sku'];
+    } else {
+        $id = $post->ID;
+        $product_meta = new WC_Product($id);
+        $sku = $product_meta->get_sku();
+    }
 
+    if ($sku){
+        return $sku;
+    } else {
+        return  __( '(not set)', 'woocommerce' );
+    }
+}
 
 /*---Move Product Title*/
 remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
index ab80484..a1fcdc8 100644 (file)
@@ -9,7 +9,7 @@
     <?php get_template_part('parts/shop-sidebar');?>    
 </div>
 <div id="enquire_button_container">
-    <a href="<?php echo get_permalink(163); ?>"><button id="enquire_button"> Enquire about this tour </button></a>
+    <a href="<?php echo get_permalink(2); ?>?sku=<?php echo $sku; ?>&title=<?php echo $title; ?>"><button id="enquire_button"> Enquire about this tour </button></a>
 </div>
 
 <?php