我正在尝试从$title
. 我接触过很多食品的功能,如get_post_meta()
,get_the_terms()
等,这似乎只能获得短期的名字从post_id
,这是不是我要找的。
我如何从 中获取术语名称term_id
?
简单的查询但由于某种原因没有显示正确的帖子,尝试显示带有每月待办事项列表术语的帖子,如果没有结果,则显示带有社区活动术语的帖子。有什么建议?
$todo_args = array(
'cat' => $my_category_id,
'posts_per_page' => 1,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'postkicker',
'field' => 'slug',
'terms' => 'monthly-to-do-list',
),
array(
'taxonomy' => 'postkicker',
'field' => 'slug',
'terms' => 'community-events',
),
),
'orderby' => 'date',
'order' => 'DESC'
);
Run Code Online (Sandbox Code Playgroud) 我一直在研究关于我的问题的网络和论坛,但我似乎无法产生正确的结果.基本上我只想显示特定产品类别的术语或产品属性.
这是我一直在研究的代码.
<fieldset class="liquor-types-control filter-controls" >
<?php
$terms = get_terms( 'wine', /*<--Product Category */ 'pa_liquor-types' /* <--Product Attribute */);
foreach ( $terms as $term ) :
?>
<label>
<input type="checkbox" value="<?php echo "." . $term->slug ?>" />
<?php echo $term->name ?>
</label>
<?php endforeach; ?>
</fieldset>
(
[errors] => Array
(
[invalid_taxonomy] => Array
(
[0] => Invalid taxonomy.
)
)
[error_data] => Array
(
)
)
Run Code Online (Sandbox Code Playgroud) 我正在使用 wordpress,希望按名称排序一级分类术语,但下面的代码没有给我想要的结果。这是我的代码:
$args = array(
'taxonomy' => 'tax-category',
'hide_empty' => 0,
'hierarchical' => 1,
'parent' => 0,
'orderby'=>'name',
'order' => 'DESC',
'fields' => 'all',
);
$rs_terms = get_terms('tax-category', $args);
Run Code Online (Sandbox Code Playgroud)
当我在 php 排序下面添加时,它完美地工作。但是想知道为什么wordpress的默认排序不能正常工作:
usort($rs_terms, function($a, $b){
return strcmp($a->name, $b->name);
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 WooCommerce 中获取产品类别,但get_terms()
功能对我不起作用。我得到一个空数组。
我做错了什么?如何获取所有 Woocommerce 产品类别术语?
我编写了一些代码,用于在基于产品类别的产品详细信息页面上显示自定义缺货消息。
function custom_backorder_message( $text, $product ){
if ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) {
if( has_term( 'bridal-line', 'product_cat' ) ) {
$text = __( 'Your piece will be handcrafted for you. Upon order we will manufacture your piece of eternity. Sadly, we can not give you a timeline, due to Covid 19, but are expecting 5-7 weeks', 'text-domain' );
}else {
$text = __( 'This product is currently out of stock, but upon order we will handcraft your piece. …
Run Code Online (Sandbox Code Playgroud) 我有一件 T 恤产品,可以选择尺寸和颜色。选择一个变体后,我希望在另一个变体中自动选择第一个可用选项。
例如,如果我有一件只有大号和特大号的白色 T 恤,以及一件只有小号和中号的绿色 T 恤,当用户选择白色时,它应该自动选择大号。但是,如果用户随后改变主意并选择绿色,则应自动选择“小”。不过,只有在其他变体中没有选择可用选项时才会发生这种情况。
虽然我可以运行脚本来选择更改时第一个启用的选项,但一旦用户再次更改为不同的颜色,WooCommerce 会发出“缺货”警告并清除他们的选择,然后我才能再次运行更改脚本。
我尝试使用 on 运行woocommerce_variation_select_change
,woocommerce_variation_has_changed
但show_variation
hide_variation
没有任何运气。
任何帮助将非常感激。以下是我到目前为止所想到的大致内容:
$(document).on( 'change', '.variations select', function( event ) {
if ( !$(this).val() ) return false;
var select = $(this);
var variations = $(this).closest('.variations');
$(variations).find('select').not(select).each(function() {
var val = $(this).val();
if ( !val || ( val && !$(this).find('option[value='+val+']:enabled') ) ) {
$(this).find('option:enabled').each(function() {
if ( $(this).attr('value') ) {
$(this).prop('selected', 'selected');
return false;
}
});
}
});
});
Run Code Online (Sandbox Code Playgroud) wordpress jquery woocommerce taxonomy-terms product-variations
我想从所有 WooCommerce 优惠券中排除具有特定属性的产品(例如 attribute_pa_brand => mybrand)。
我遵循了这个答案,从 Woocommerce 中的优惠券使用中排除具有 2 个特定属性术语的变体 ,但它似乎仅适用于Variable Product类型,而我只需要它用于Simple Product。
我将不胜感激任何答复。
我有一个由 WooCommerce 提供支持的电子商务网站。我使用产品变体来允许我的客户为其产品选择特定配置。
我使用以下代码列出特定产品属性的术语名称:
$available_pa_colors = wc_get_product_terms( $product->get_id(), 'pa_colors' );
Run Code Online (Sandbox Code Playgroud)
而且效果很好。
但是,当将默认排序顺序从“自定义排序”更改为“术语 ID”时,我什么也没得到(没有显示术语名称)。
我做了一些研究,似乎 wc_get_product_terms 不适用于排序。
如何让这些术语按术语 ID 排序?
任何有关此的曲目都将受到赞赏。
如果我已经拥有现有的产品属性,然后使用下面的函数,它会从产品中删除现有的属性,并将其替换为这一属性。
我只想以编程方式用新值更新这个属性值。
我是否必须先使用 get_post_meta 读取现有属性数组并更新它?我只是想看看是否有替代方法。
function update_internalSKU() {
$product_id = 850;
$product_attributes = array();
$product_attributes['internalSKU'] = array(
'name' => 'internalSKU',
'value' => 'b8de7569042',
'position' => 1,
'is_visible' => 0,
'is_variation' => 0,
'is_taxonomy' => 0
);
update_post_meta( $product_id ,'_product_attributes', $product_attributes);
}
update_internalSKU();
Run Code Online (Sandbox Code Playgroud) taxonomy-terms ×10
wordpress ×9
php ×8
woocommerce ×7
coupon ×1
jquery ×1
loops ×1
product ×1
sorting ×1