Support » Plugin: WooCommerce » Can’t get regular price for the product

  • Hi,

    I have this code in my custom plugin:

    	$product = wc_get_product($item['product_id']);	
    	echo $product->get_regular_price();

    It worked in previous WC version, but it won’t in version 3.0. Some things probably changed, how to get this info (I don’t want formatted price)?

Viewing 7 replies - 1 through 7 (of 7 total)
  • This should work. That is the correct usage (assuming that $item[‘product_id’] is a valid product id). What specifically is happening?

    Well nothing. If I turn on debugging, I only get this:

    Notice: The “woocommerce_get_product_attributes” hook uses out of date data structures and is deprecated since version 3.0.0! Use woocommerce_product_get_attributes instead. in /home/homejungles/public_html/wp-includes/functions.php on line 3829

    This is my code (short version) if you want to take a look:

    https://pastebin.com/0rT66WXZ

    UPDATE: It does work with non-variable products, but not with the variations…

    Plugin Author Mike Jolley

    (@mikejolley)

    See if $item[‘product_id’] is set. Item is an object so it has getters too usually.

    Solved, it was some kind of error with quantity getting, it affected rest of the code (it wasn’t in the example).

    So, if you are interested to know what it is:

    This won’t work (but it worked before):

    $product_info = $item['item_meta'];
    $quantity = $product_info['_qty'][0];

    And this works instead:

    $quantity = $item['qty'];

    • This reply was modified 2 years, 10 months ago by Nikola Tomic.
    Plugin Author Mike Jolley

    (@mikejolley)

    What about $item->get_quantity();

    Yep, that could also work

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Can’t get regular price for the product’ is closed to new replies.