title: Product type IF condition not working in WooCommerce
body: <p>My product type <code>IF</code> condition is not working correctly.  The intention is as follows:</p>
  
  <p><code>IF</code> product type = <code>variable</code>, do X, </p>
  
  <p><code>elseif</code> product type = <code>simple</code>, do Y.  </p>
  
  <p>Full code follows:</p>
  
  <pre><code>$product = new WC_Product( get_the_ID() );
  
  if( $product-&gt;is_type( 'variable' ) ){
  
  /* as per https://wordpress.stackexchange.com/questions/276941/woocommerce-add-extra-field-to-variation-product/277556 
  based on http://www.remicorson.com/woocommerce-custom-fields-for-variations/ */
  
  add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 );
  add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );
  add_filter( 'woocommerce_available_variation', 'load_variation_settings_fields' );
  
  function variation_settings_fields( $loop, $variation_data, $variation ) {
      woocommerce_wp_text_input(
          array(
              'id'            =&gt; "custom_MPN{$loop}",
              'name'          =&gt; "custom_MPN[{$loop}]",
              'value'         =&gt; get_post_meta( $variation-&gt;ID, 'custom_MPN', true ),
              'label'         =&gt; __( 'MPN variation', 'woocommerce' ),
              'desc_tip'      =&gt; true,
              'description'   =&gt; __( 'Manufacturer Product Number (hand-coded field).', 'woocommerce' ),
              'wrapper_class' =&gt; 'form-row form-row-full',
          )
      );
  
      woocommerce_wp_text_input(
          array(
              'id'            =&gt; "custom_GTIN{$loop}",
              'name'          =&gt; "custom_GTIN[{$loop}]",
              'value'         =&gt; get_post_meta( $variation-&gt;ID, 'custom_GTIN', true ),
              'label'         =&gt; __( 'GTIN variation', 'woocommerce' ),
              'desc_tip'      =&gt; true,
              'description'   =&gt; __( 'Global Trade Item Number (hand-coded field).', 'woocommerce' ),
              'wrapper_class' =&gt; 'form-row form-row-full',
          )
      );
  }
  
  function save_variation_settings_fields( $variation_id, $loop ) {
      $text_field = $_POST['custom_MPN'][ $loop ];
  
      if ( ! empty( $text_field ) ) {
          update_post_meta( $variation_id, 'custom_MPN', esc_attr( $text_field ));
      }
  
      $text_field = $_POST['custom_GTIN'][ $loop ];
  
      if ( ! empty( $text_field ) ) {
          update_post_meta( $variation_id, 'custom_GTIN', esc_attr( $text_field ));
      }
  }
  
  function load_variation_settings_fields( $variation ) {     
      $variation['custom_MPN'] = get_post_meta( $variation[ 'variation_id' ], 'custom_MPN', true );
      $variation['custom_GTIN'] = get_post_meta( $variation[ 'variation_id' ], 'custom_GTIN', true );
  
      return $variation;
  }
  
  
  
  } elseif( $product-&gt;is_type( 'simple' ) ){
  
  
  
  /* Product identification meta data below the product title: GTIN */
  
  // https://businessbloomer.com/woocommerce-add-text-add-cart-single-product-page/   
  add_action( 'woocommerce_single_product_summary', 'custom_data_above_add_to_cart_button', 6 );
  function custom_data_above_add_to_cart_button( $product ) {
  
  // https://wordpress.stackexchange.com/a/165757/135006
  // Be wary - this solution was needed to make code work: https://stackoverflow.com/a/6110690/9095603
  
  // GTIN
        if ( get_post_meta( get_the_id(), 'wccaf_gtin', true ) ) {
  
          echo '&lt;div class="wccaf_gtin"&gt;GTIN: '.get_post_meta( get_the_id(), 'wccaf_gtin', true ).'&lt;/div&gt;';
  
      } else {
  
          echo '&lt;div class="wccaf_gtin"&gt;GTIN unspecified.&lt;/div&gt;';
  
      }
  
  
  // MPN
        if ( get_post_meta( get_the_id(), 'wccaf_mpn', true ) ) {
  
          echo '&lt;div class="wccaf_mpn"&gt;MPN: '.get_post_meta( get_the_id(), 'wccaf_mpn', true ).'&lt;/div&gt;';
  
      } else {
  
          echo '&lt;div class="wccaf_mpn"&gt;MPN unspecified.&lt;/div&gt;';
  
      }
  
  }
  
  
  
  }
  </code></pre>
  
  <p><strong>Edit: The result of the conditional not being applied is that certain values are displayed that I want suppressed, in the case of products with many variations (e.g. colors, sizes), as illustrated in the screenshot:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/kkr0s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kkr0s.png" alt="enter image description here"></a></p>
  
  <p><strong>Edit 2 - <code>print_r($product)</code> gives:</strong></p>
  
  <pre><code>WC_Product Object ( [object_type:protected] =&gt; product [post_type:protected] =&gt; product [cache_group:protected] =&gt; products [data:protected] =&gt; Array ( [name] =&gt; [slug] =&gt; [date_created] =&gt; [date_modified] =&gt; [status] =&gt; [featured] =&gt; [catalog_visibility] =&gt; visible [description] =&gt; [short_description] =&gt; [sku] =&gt; [price] =&gt; [regular_price] =&gt; [sale_price] =&gt; [date_on_sale_from] =&gt; [date_on_sale_to] =&gt; [total_sales] =&gt; 0 [tax_status] =&gt; taxable [tax_class] =&gt; [manage_stock] =&gt; [stock_quantity] =&gt; [stock_status] =&gt; instock [backorders] =&gt; no [sold_individually] =&gt; [weight] =&gt; [length] =&gt; [width] =&gt; [height] =&gt; [upsell_ids] =&gt; Array ( ) [cross_sell_ids] =&gt; Array ( ) [parent_id] =&gt; 0 [reviews_allowed] =&gt; 1 [purchase_note] =&gt; [attributes] =&gt; Array ( ) [default_attributes] =&gt; Array ( ) [menu_order] =&gt; 0 [virtual] =&gt; [downloadable] =&gt; [category_ids] =&gt; Array ( ) [tag_ids] =&gt; Array ( ) [shipping_class_id] =&gt; 0 [downloads] =&gt; Array ( ) [image_id] =&gt; [gallery_image_ids] =&gt; Array ( ) [download_limit] =&gt; -1 [download_expiry] =&gt; -1 [rating_counts] =&gt; Array ( ) [average_rating] =&gt; 0 [review_count] =&gt; 0 ) [supports:protected] =&gt; Array ( ) [id:protected] =&gt; 0 [changes:protected] =&gt; Array ( ) [object_read:protected] =&gt; 1 [extra_data:protected] =&gt; Array ( ) [default_data:protected] =&gt; Array ( [name] =&gt; [slug] =&gt; [date_created] =&gt; [date_modified] =&gt; [status] =&gt; [featured] =&gt; [catalog_visibility] =&gt; visible [description] =&gt; [short_description] =&gt; [sku] =&gt; [price] =&gt; [regular_price] =&gt; [sale_price] =&gt; [date_on_sale_from] =&gt; [date_on_sale_to] =&gt; [total_sales] =&gt; 0 [tax_status] =&gt; taxable [tax_class] =&gt; [manage_stock] =&gt; [stock_quantity] =&gt; [stock_status] =&gt; instock [backorders] =&gt; no [sold_individually] =&gt; [weight] =&gt; [length] =&gt; [width] =&gt; [height] =&gt; [upsell_ids] =&gt; Array ( ) [cross_sell_ids] =&gt; Array ( ) [parent_id] =&gt; 0 [reviews_allowed] =&gt; 1 [purchase_note] =&gt; [attributes] =&gt; Array ( ) [default_attributes] =&gt; Array ( ) [menu_order] =&gt; 0 [virtual] =&gt; [downloadable] =&gt; [category_ids] =&gt; Array ( ) [tag_ids] =&gt; Array ( ) [shipping_class_id] =&gt; 0 [downloads] =&gt; Array ( ) [image_id] =&gt; [gallery_image_ids] =&gt; Array ( ) [download_limit] =&gt; -1 [download_expiry] =&gt; -1 [rating_counts] =&gt; Array ( ) [average_rating] =&gt; 0 [review_count] =&gt; 0 ) [data_store:protected] =&gt; WC_Data_Store Object ( [instance:WC_Data_Store:private] =&gt; WC_Product_Data_Store_CPT Object ( [internal_meta_keys:protected] =&gt; Array ( [0] =&gt; _visibility [1] =&gt; _sku [2] =&gt; _price [3] =&gt; _regular_price [4] =&gt; _sale_price [5] =&gt; _sale_price_dates_from [6] =&gt; _sale_price_dates_to [7] =&gt; total_sales [8] =&gt; _tax_status [9] =&gt; _tax_class [10] =&gt; _manage_stock [11] =&gt; _stock [12] =&gt; _stock_status [13] =&gt; _backorders [14] =&gt; _sold_individually [15] =&gt; _weight [16] =&gt; _length [17] =&gt; _width [18] =&gt; _height [19] =&gt; _upsell_ids [20] =&gt; _crosssell_ids [21] =&gt; _purchase_note [22] =&gt; _default_attributes [23] =&gt; _product_attributes [24] =&gt; _virtual [25] =&gt; _downloadable [26] =&gt; _download_limit [27] =&gt; _download_expiry [28] =&gt; _featured [29] =&gt; _downloadable_files [30] =&gt; _wc_rating_count [31] =&gt; _wc_average_rating [32] =&gt; _wc_review_count [33] =&gt; _variation_description [34] =&gt; _thumbnail_id [35] =&gt; _file_paths [36] =&gt; _product_image_gallery [37] =&gt; _product_version [38] =&gt; _wp_old_slug [39] =&gt; _edit_last [40] =&gt; _edit_lock ) [extra_data_saved:protected] =&gt; [updated_props:protected] =&gt; Array ( ) [meta_type:protected] =&gt; post [object_id_field_for_meta:protected] =&gt; ) [stores:WC_Data_Store:private] =&gt; Array ( [coupon] =&gt; WC_Coupon_Data_Store_CPT [customer] =&gt; WC_Customer_Data_Store [customer-download] =&gt; WC_Customer_Download_Data_Store [customer-download-log] =&gt; WC_Customer_Download_Log_Data_Store [customer-session] =&gt; WC_Customer_Data_Store_Session [order] =&gt; WC_Order_Data_Store_CPT [order-refund] =&gt; WC_Order_Refund_Data_Store_CPT [order-item] =&gt; WC_Order_Item_Data_Store [order-item-coupon] =&gt; WC_Order_Item_Coupon_Data_Store [order-item-fee] =&gt; WC_Order_Item_Fee_Data_Store [order-item-product] =&gt; WC_Order_Item_Product_Data_Store [order-item-shipping] =&gt; WC_Order_Item_Shipping_Data_Store [order-item-tax] =&gt; WC_Order_Item_Tax_Data_Store [payment-token] =&gt; WC_Payment_Token_Data_Store [product] =&gt; WC_Product_Data_Store_CPT [product-grouped] =&gt; WC_Product_Grouped_Data_Store_CPT [product-variable] =&gt; WC_Product_Variable_Data_Store_CPT [product-variation] =&gt; WC_Product_Variation_Data_Store_CPT [shipping-zone] =&gt; WC_Shipping_Zone_Data_Store [webhook] =&gt; WC_Webhook_Data_Store ) [current_class_name:WC_Data_Store:private] =&gt; WC_Product_Data_Store_CPT [object_type:WC_Data_Store:private] =&gt; product-simple ) [meta_data:protected] =&gt; )
  </code></pre>