class Product { private $id; private $price; // Constructor public function __construct($id, $price) { $this->id = $id; $this->price = $price; } // Getters public function getId() { return $this->id; } public function getPrice() { return $this->price; } } $product = new Product(1, 100); // create new product echo $product->getPrice(); // output: 100
$product_id = get_the_ID(); // retrieve the product ID from current WordPress post $price = wc_get_product($product_id)->get_price(); // obtain the price of WooCommerce product echo $price; // output the price on the pagePackage/Library: The getPrice() method is commonly used in various PHP libraries and frameworks such as Laravel, Symfony, and Magento. It is also used in e-commerce platforms like WooCommerce and Shopify. However, as it is a basic method, it does not belong to any specific package or library.