php - WooCommerce:比较变体属性值
问题描述
我正在销售成对出现的产品。因此,当下订单时,通常它包含两个变体:“顶部”和“底部”。
通常两种变体都包含相同的属性值,除了一个属性。
我想比较这两种变体,以查看除一个之外的所有属性值是否相同。
我正在尝试使用以下代码片段来做到这一点:
if( $product->is_type( 'variable' ) ){
// Loop through available product variation data
foreach ( $product->get_available_variations() as $key => $variation ) {
// Loop through the product attributes for this variation
foreach ($variation['attributes'] as $attribute => $term_slug ) {
// Get the taxonomy slug
$taxonmomy = str_replace( 'attribute_', '', $attribute );
// Get the attribute label name
$attr_label_name = wc_attribute_label( $taxonmomy );
// Display attribute labe name
$term_name = get_term_by( 'slug', $term_slug, $taxonmomy )->name;
解决方案
推荐阅读
- python - 从子类(Python)访问类属性?
- r - 从栅格堆栈 R 中删除线性趋势
- after-effects - After Effects 表达式(如果图层是 CompItem)
- ios - 来自加速度计的数据的用户位置
- javascript - 打印预览的 Chrome 问题
- angular - 我无法让我的 Angular 6 *ngIf 语句工作
- ios - 如何在init Swift中获取IF语句之外的变量
- r - 如何从 R 包中的动态库评估 C 函数?
- javascript - Cannot select text within an iframe on iOS Safari
- sql - SQL query using Firebird and foreign characters causes a malformed string error