【发布时间】:2021-11-30 09:07:42
【问题描述】:
错误代码:
未捕获的错误:在 D:\Program 中找不到类“inc\woocommerce\Product” 文件\Xampp\htdocs\aliahmad\wp-content\themes\aliahmad\taxonomy-product_cat.php:51 堆栈跟踪:#0 D:\Program Files\Xampp\htdocs\aliahmad\wp-includes\template-loader.php(106): include() #1 D:\Program Files\Xampp\htdocs\aliahmad\wp-blog-header.php(19): require_once('D:\Program File...') #2 D:\Program Files\Xampp\htdocs\aliahmad\index.php(17): require('D:\Program File...') #3 {main} 在 D:\Program Files\Xampp\htdocs\aliahmad\wp- 中抛出 content\themes\aliahmad\taxonomy-product_cat.php 第 51 行
这是我的php文件实现:(文件:inc/woocommerce/Product.php)
class Product {
protected $query;
public $name;
public $sku;
public $price;
public function __construct( $id ) {
$this->query = wc_get_product( $id );
$this->name = $this->query->get_name();
$this->sku = $this->query->get_sku();
$this->price = $this->query->get_price();
}
}
这是我创建的类实例:(文件:taxonomy-product_cat.php)
global $product_query;
// use inc\woocommerce\Product;
foreach ( $product_query->posts as $product ) {
new inc\woocommerce\Product( $product->id );
}
这是我的文件层次结构:
inc
|
woocommerce
|
Product.php
taxonomy-product_cat.php
感谢所有帮助
【问题讨论】:
-
是的,谢谢。