【问题标题】:How can I check if a product is part of a grouped product (WooCommerce)如何检查产品是否是分组产品的一部分(WooCommerce)
【发布时间】:2016-02-12 07:19:18
【问题描述】:

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

这就是我希望代码运行的方式(如果产品是分组产品的子产品 - 显示永久链接按钮)

我不再希望检查产品是否为外部类型。

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>';
        }
    }
}

【问题讨论】:

    标签: php woocommerce


    【解决方案1】:

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

    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>';
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-18
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-09
      • 2014-11-14
      • 1970-01-01
      相关资源
      最近更新 更多