wordpress - WooCommerce:从匹配的属性中获取产品变体 ID

标签 wordpress woocommerce product variations

我如何从自定义产品循环中获取产品变体 ID。
我有变化属性,比如,

{ 'pa_color'=>'red','pa_size'=>'large'}

最佳答案

要匹配的属性集是

[
    'attribute_pa_color' => 'blue',
    'attribute_pa_size' => 'small',
];

下面是我最终创建的函数来实现这一点:
/**
 * Find matching product variation
 *
 * @param $product_id
 * @param $attributes
 * @return int
 */
function find_matching_product_variation_id($product_id, $attributes)
{
    return (new \WC_Product_Data_Store_CPT())->find_matching_product_variation(
        new \WC_Product($product_id),
        $attributes
    );
}

关于wordpress - WooCommerce:从匹配的属性中获取产品变体 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53958871/

相关文章:

wordpress - 产品图片不显示(Woocommerce)

php - 添加预计交货日期范围?

mysql - SQL 和 WPDB 的困难,特别是在 WHERE 子句中

javascript - 坚持顶部菜单差距

php - 在 php 中生成缩略图,发布到 Azure 计算机视觉 API

android - 如何在 JAVA/Android 中使用 Woocommerce REST API 的 'POST' Http Verb?

Mysql根据1行更新6行

php - 单一产品页面 - 从相关产品中排除当前产品

api - 使用亚马逊(产品广告)API 禁用加入按钮

php - WordPress - 尝试使用计数器将今天的帖子分为上午和下午