• 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)
  • Plugin Contributor Claudiu Lodromanean

    (@claudiulodro)

    This should work. That is the correct usage (assuming that $item[‘product_id’] is a valid product id). What specifically is happening?

    Thread Starter Nikola Tomic

    (@johnnynt)

    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

    Thread Starter Nikola Tomic

    (@johnnynt)

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

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

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

    Thread Starter Nikola Tomic

    (@johnnynt)

    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 7 years, 8 months ago by Nikola Tomic.
    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    What about $item->get_quantity();

    Thread Starter Nikola Tomic

    (@johnnynt)

    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.