Php 如何检查产品是否属于分组产品(WooCommerce)的一部分

Php 如何检查产品是否属于分组产品(WooCommerce)的一部分,php,woocommerce,Php,Woocommerce,目前,我的函数仅在执行前检查产品是否为“外部”类型,如何更改函数以检查产品是否为“分组”产品的一部分。然后回显包含已配置的父产品permalink的按钮 这是我希望代码运行的方式(如果产品是分组产品的子产品-ShowPermalink按钮) 我不想再检查产品是否为外部类型 function parent_permalink_button() { global $post; if( function_exists('get_product') ){ $product

目前,我的函数仅在执行前检查产品是否为“外部”类型,如何更改函数以检查产品是否为“分组”产品的一部分。然后回显包含已配置的父产品permalink的按钮

这是我希望代码运行的方式(如果产品是分组产品的子产品-ShowPermalink按钮)

我不想再检查产品是否为外部类型

function parent_permalink_button() {
    global $post;
    if( function_exists('get_product') ){
        $product = get_product( $post->ID );
        if( $product->is_type( 'external' ) ){
            $permalink = get_permalink($post->post_parent);
            echo '<a class="button" href="'.$permalink.'">Compare Deals</a>';
        }
    }
}
function parent\u permalink\u按钮(){
全球$员额;
如果(函数_存在('get_product')){
$product=获取产品($post->ID);
如果($product->is_类型('external')){
$permalink=get\u permalink($post->post\u parent);
回声';
}
}
}

我认为这可能有效,但必须对其进行测试

function parent_permalink_button() {
   global $post; 
   if( $post->post_parent != 0 ){ 
       $permalink = get_permalink($post->post_parent);
       echo '<a class="button" href="'.$permalink.'">Compare Deals</a>';
    }
}
function parent\u permalink\u按钮(){
全球$员额;
如果($post->post_parent!=0){
$permalink=get\u permalink($post->post\u parent);
回声';
}
}