[英]Woocommerce - add surcharge in cart based on weight only to some categories (or to all cart except some categories)
[英]All categories except some categoryID
if ($Category->CategoryID > 0)
适用于所有类别。 如何消除一些类别ID,例如1、2和3。
if ($Category->CategoryID > 0) {
// If we are below the max depth, and there are some child categories
// in the $ChildCategories variable, do the replacement.
if ($Category->Depth < $MaxDisplayDepth && $ChildCategories != '') {
$CatList = str_replace('{ChildCategories}', '<span class="ChildCategories">'.Wrap(T('Child Categories:'), 'b').' '.$ChildCategories.'</span>', $CatList);
$ChildCategories = '';
}
if ($Category->Depth >= $MaxDisplayDepth && $MaxDisplayDepth > 0) {
if ($ChildCategories != '')
$ChildCategories .= ', ';
$ChildCategories .= Anchor(Gdn_Format::Text($Category->Name), '/categories/'.$Category->UrlCode);
} else if (($DoHeading || $DoHeadings) && $Category->Depth == 1) {
$CatList .= '<li class="Item CategoryHeading Title Info Depth1 Category-'.$Category->UrlCode.' '.$CssClasses.'">
<div class="ItemContent Category">'.Anchor(Gdn_Format::Text($Category->Name), '/categories/'.$Category->UrlCode).'</div>'
.GetOptions($Category, $this).'
</li>';
$Alt = FALSE;
} else {
$LastComment = UserBuilder($Category, 'LastComment');
$AltCss = $Alt ? ' Alt' : '';
$Alt = !$Alt;
$CatList .= '<li class="'.$Category->Depth.$AltCss.' Category-'.$Category->UrlCode.' '.$CssClasses.'">
<div class="SubMenu1 Category '.$CssClasses.'">'
.Anchor(Gdn_Format::Text($Category->Name), '/categories/'.$Category->UrlCode, 'Title')
.GetOptions($Category, $this)
.Wrap($Category->Description, 'div', array('class' => 'CategoryDescription'))
.'<div class="Meta2">
';
if ($Category->LastCommentID != '' && $Category->LastDiscussionTitle != '') {
$CatList .= '<span class="LastDiscussionTitle">'.sprintf(
T('Most recent: %1$s by %2$s'),
Anchor(SliceString($Category->LastDiscussionTitle, 40), '/discussion/'.$Category->LastDiscussionID.'/'.Gdn_Format::Url($Category->LastDiscussionTitle)),
UserAnchor($LastComment)
).'</span>'
.'<span class="LastCommentDate">'.Gdn_Format::Date($Category->DateLastComment).'</span>';
}
$CatList .= '</div>
</div>
</li>';
}
}
如果您特别不希望类别1、2和3(非常有限的解决方案):
if ($Category->CategoryID > 3)
或者,如果您知道不需要的类别:
if (!in_array($Category->CategoryID, array(1, 2, 3)))
或者,如果您想在代码的前面找出不需要的类别:
$bad_categories = array();
//populate $bad_categories to fit your needs...
if (!in_array($Category->CategoryID, $bad_categories))
例如,您只需要检查不需要的数字。
改变这条线
if ($Category->CategoryID > 0) {
对此
if ($Category->CategoryID != 1) {
这将意味着您不会获得类别1。
要删除几个类别,请使用此选项。
if ($Category->CategoryID != 1 && $Category->CategoryID != 2) {
您可以无限期地继续进行此操作。 但是正如Abhishek kadadi在评论中所建议的那样,使用MySQL可能也是一种解决方案。
但是显然,如果添加任何其他类别,则如果看不到它,则需要对其进行硬编码。
可能您可以在数据库中添加另一个字段,即。 可见的,将显示可见的,等等。然后您可以对可见的MySQL进行MySQL查询,只需添加一个新类别,可见性就足够了。
考虑SQL语句中的过滤器类别,如下所示:
SELECT * FROM table_name WHERE field_name NOT IN (1,2,3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.