I'm writing a plugin that allows customers to request additional information via an email form about a woocommerce product. I'm able to pull in the Simple product information, but when I try to pull the variation name and SKU on a variable product, it still only brings back the parent product information, or the white screen of death. Either way, not a favorable outcome. At this point I'd settle for the parent product with additional variable fields for the attributes. Any help is appreciated.
Here's what I have so far:
function lsg_before_info_req_button() {
global $product;
if( $product->is_type( 'simple' ) ) {
if( class_exists( 'lsg_info_req' ) ) {
echo "<input type=\"hidden\" name=\"info_request\" value=\"". esc_attr( $product->id ) . "\" />";
echo "<button type=\"submit\" class=\"info_req_button button alt\">" . apply_filters('info_req_text', __( 'Email for More Information', 'woocommerce' ), $product->product_type) . "</button>";}
else {
echo "<button type=\"submit\" onclick='this.form.action=\"" . add_query_arg('product_id', $product->id, get_permalink( get_option('lsg_info_req_page_id') )) . "\";' class=\"info_req_button button alt\">" . apply_filters('info_req_text', __( 'Email for More Information', 'woocommerce' ), $product->product_type) . "</button>";}}
elseif( $product->is_type( 'variable' ) ) {
echo "<div class=\"single_variation_wrap\" style=\"display:none;\">";
echo "<div class=\"single_variation\"></div>";
echo "<div class=\"variations_button\">";
echo "<input type=\"hidden\" name=\"variation_id\" value=\"\" />";
woocommerce_quantity_input();
if( class_exists( 'lsg_info_req' ) ) {
echo "<button type=\"submit\" class=\"info_req_button button alt\">" . apply_filters('info_req_text', __( 'Email for More Information', 'lsg' ), $product->product_type) . "</button>";}
else {
echo "<button type=\"submit\" onclick='this.form.action=\"" . add_query_arg('variation_id', $variation->id, get_permalink( get_option('lsg_info_req_page_id') )) . "\";' class=\"info_req_button button alt\">" . apply_filters('info_req_text', __( 'Email for More Information', 'lsg' ), $product->product_type) . "</button>";}
echo "<input type=\"hidden\" name=\"add-to-quote\" value=\"" . $variation->id . "\" />";
echo "<input type=\"hidden\" name=\"variation_id\" value=\"" . esc_attr( $post->ID ) . "\" />";