WooCommerce-通过主题覆盖wc-formatting-functions.php文件无效
当我在WooCommerce插件文件夹中更改核心文件时,我试图将我的代码包含在wc formatting functions.php文件中,并且该文件正常工作 现在,我在我的主题文件夹中创建了WooCommerce-通过主题覆盖wc-formatting-functions.php文件无效,php,wordpress,woocommerce,categories,product,Php,Wordpress,Woocommerce,Categories,Product,当我在WooCommerce插件文件夹中更改核心文件时,我试图将我的代码包含在wc formatting functions.php文件中,并且该文件正常工作 现在,我在我的主题文件夹中创建了woocommerce文件夹,并在其中复制了wc格式化函数.php文件,试图覆盖,但它不起作用 我试图在函数中插入此代码: if(is_product_category('mattress')){ echo "mattress category"; } else if(is_product_cate
woocommerce
文件夹,并在其中复制了wc格式化函数.php
文件,试图覆盖,但它不起作用
我试图在函数中插入此代码:
if(is_product_category('mattress')){
echo "mattress category";
}
else if(is_product_category('pillows')){
echo "pillows category";
}
else if(is_product_category('protectors')){
echo "protectors category";
}
else if(is_product_category('toppers')){
echo "toppers category";
}
else if(is_product_category('foldable-mattress')){
echo "foldable-mattress category";
}
就在wc-formatting-functions.php中的这些行之后:
$formatted_price = ( $negative ? '-' : '' ) . sprintf( $price_format, '<span class="woocommerce-Price-currencySymbol">' . get_woocommerce_currency_symbol( $currency ) . '</span>', $price );
$return = '<span class="woocommerce-Price-amount amount">' . $formatted_price . '</span>';
$formatted\u price=($negative?'-':'')。sprintf($price_format,''.get_-woocmerce_-currency_-symbol($currency)。''$price);
$return=''$格式为“价格”;
我做错了什么?作为
wc格式化函数。php
是WooCommerce核心文件,而不是模板文件,您将无法使其在主题文件夹中的WooCommerce
文件夹中工作
无法通过主题将wc formatting functions.php
核心文件重写为模板文件。
根据您希望在何处使用代码,您可以尝试在相关挂钩中使用它,如:
add_filter( 'woocommerce_cart_product_price', 'filter_woocommerce_cart_product_price', 10, 2 );
function filter_woocommerce_cart_product_price( $wc_price, $product ) {
// some code
return $wc_price;
};
由于是\u product\u category()
条件目标类别页面存档,您可以覆盖相关的woocommerce模板,具体取决于您希望在何处使用代码
您甚至可以将代码插入活动主题的function.php文件中,嵌入到可以重用的函数中
但是,如果您想使用条件来定位某个类别,则必须使用例如has\u term('matd','product\u cat')
参考资料: