2016-02-08 41 views
0

在我的functions.php文件中,我有一些remove_actions和add_filters爲woocommerce運行,但問題是這些函數運行於所有woocommerce產品類型。if語句分組產品參考woocommerce

我想包裝一個簡單的if語句圍繞鉤子/過濾器我只能運行分組產品頁面問題是我不知道woocommerce如何引用這些頁面繼承我現在擁有的。

remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); 

繼承人我想要做的,但我不知道$ groupped_product的正確引用。

if ($grouped_product) { 
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); 
} 

我有兩個和的add_filter卸下一個動作,我想在我的functions.php追加僅在分組產品頁面執行我只需要在第二個代碼塊在第一組括號正確的參考以上。

嘗試這種代碼,但它不工作..

if (is_product() and $product->is_type('grouped')) { 
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); 
} 

功能PHP文件

<?php 
function theme_enqueue_styles() { 

$parent_style = 'parent-style'; 

wp_enqueue_style($parent_style, get_template_directory_uri() .  '/style.css'); 
wp_enqueue_style('child-style', 
    get_stylesheet_directory_uri() . '/style.css', 
    array($parent_style) 
); 
} 
add_action('wp_enqueue_scripts', 'theme_enqueue_styles'); 

//Remove cart options from under short description. 

    remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); 

//Filter below adds new tab and returns cart options within tab. 

add_filter('woocommerce_product_tabs', 'woo_paym_product_tab'); 

function woo_paym_product_tab($tabs) { 

    // Adds the new tab 

     $tabs['paym-plans'] = array('title' => __('Contract Deals', 'woocommerce'), 'priority' => 10, 'callback' => 'woo_paym_product_tab_content'); 

    return $tabs; 

} 

function woo_paym_product_tab_content() { 

    // The new tab content 

     woocommerce_template_single_add_to_cart(); 

} 

//Filter below changes tab priority to display price plans first. 

add_filter('woocommerce_product_tabs', 'sb_woo_move_description_tab', 98); 

function sb_woo_move_description_tab($tabs) { 



    $tabs['paym-plans']['priority'] = 10; 

    $tabs['description']['priority'] = 20; 

    $tabs['additional_information']['priority'] = 30; 

    return $tabs; 

} 
?> 
+0

http://bryceadams.com/change-add-cart-text-woocommerce/這傢伙確實相似,但具有添加到購物車文本我怎麼能複製他的技術,但有刪除行動分組的產品只有東西? – Scott

回答

0

檢查$產品 - > is_type( '組合')不會在這裏幫助...

請檢查代碼提供給您的任何幫助..

global $post; 
if($post->post_parent != 0){ 
    echo 'is part of a group'; 
} 
+0

嗨,感謝您花時間幫助我:)所以我將代碼粘貼到wordpress中的functions.php文件中,並在分組產品頁面中搜索字符串'是組的一部分',但無法找到它在頁面源中。我不明白爲什麼woocommerce使這個如此困難,有什麼想法? – Scott

+0

請將您添加的代碼發佈到function.php中。 – PHPExpert

+0

我添加了你的代碼/ \ – Scott

0

解決了問題的竅門是將其更改爲過濾器。

add_filter('woocommerce_single_product_summary', 'filter_grouped_cart'); 

function filter_grouped_cart(){ 
    global $post; 
    if(function_exists('get_product')){ 
    $product = get_product($post->ID); 
    if($product->is_type('grouped')){ 
     remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); 
} 
} 
}