• Hello there,

    Could someone kindly help me to figure out how to find the product type of the product being edited in dashboard? I can query to see if it’s a product or not, but I’ve not being able to figure out a way to find out if it’s a simple product or any other product. I am trying to add a custom field to add/edit product screen so I would like to add it to General tab if it’s a Simple product and to somewhere else if it’s not a Simple product.

    Many thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    Hello there,
    You can use $product->get_type() to return the product type of the product you’re working on.

    Replace $product with your product object.
    You can find more info about this method here: https://woocommerce.github.io/code-reference/classes/WC-Product.html#method_get_type

    Thread Starter Pradeep

    (@pmaheepala)

    Hello @nicolamustone,

    Many thanks for the quick reply. Does that mean something like this would determine if I am adding/editing a ‘simple’ product? I gave it a try but it throws the ‘there has been a critical error in this website’, error.

    global $woocommerce, $post, $typenow, $product;
    	if (is_edit_page() && $product->is_type('simple')) {
    		echo "hello world";
    	
    	}
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to find the product type being edited’ is closed to new replies.