2016-02-12 64 views
0

目前我的功能只在產品執行前檢查產品是否爲'外部',如何更改功能以檢查產品是否屬於'分組'的woocommerce產品。然後回顯包含已配置的父產品永久鏈接的按鈕。我如何檢查產品是否爲分組產品的一部分(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>'; 
     } 
    } 
} 

回答

2

我認爲這可能會工作,但將不得不測試它。

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>'; 
    } 
} 
相關問題