79597261

Date: 2025-04-28 20:45:28
Score: 0.5
Natty:
Report link

This is actually a PHP syntax typo not a WooCommerce function misunderstanding. The line

$_product = wc_get_product('$courseID');

asks for a product with an ID that matches a string that starts with a dollar sign (and is followed by eight other letters). Why? PHP does not evaluate variables inside single-quoted strings the way it does for double-quoted strings.

The $courseID variable holds a number, and the string 7172 can also be "cast" to a number, so neither of them fail. The following two corrected versions of the line are equivalent (unless strict typing is turned on):

$_product = wc_get_product("$courseID");
$_product = wc_get_product( $courseID );
Reasons:
  • Blacklisted phrase (0.5): Why?
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: David