2016-02-26 69 views
2

我設計Woocommerce單品頁, 我設計的產品頁面我創造了這個功能 安排「選擇變異」選擇和「添加到購物車「按鈕安排Woocommerce可變產品數據

function filter_grouped_cart(){ 
    global $post; 
    if(function_exists('get_product')){ 
     $product = get_product($post->ID); 
     if($product->is_type('variable')){ 
      remove_action('woocommerce_variable_add_to_cart', 
        'woocommerce_variable_add_to_cart', 30); 
      add_action('woocommerce_before_single_product_summary', 
        'woocommerce_variable_add_to_cart', 45); 

      remove_action('woocommerce_single_variation', 
        'woocommerce_single_variation_add_to_cart_button', 20); 
      add_action('woocommerce_before_single_product_summary', 
        'woocommerce_single_variation_add_to_cart_button', 60); 
     } 
    } 
} 

我用條件邏輯,因爲沒有它,我簡單的產品頁面什麼也沒有顯示。 此代碼工作正常,但我有這方面的行動和他們的優先

remove_action('woocommerce_before_single_product_summary', 
     'woocommerce_show_product_images', 20); 
add_action('woocommerce_single_product_summary', 
     'woocommerce_show_product_images', 20); 

remove_action('woocommerce_single_product_summary', 
     'woocommerce_template_single_title', 5); 
add_action('woocommerce_before_single_product_summary', 
     'woocommerce_template_single_title', 30); 

remove_action('woocommerce_after_single_product_summary', 
     'woocommerce_output_product_data_tabs', 10); 
add_action('woocommerce_before_single_product_summary', 
     'the_content', 40); 

remove_action('woocommerce_single_product_summary', 
     'woocommerce_template_single_price', 10); 
add_action('woocommerce_before_single_product_summary', 
     'woocommerce_template_single_price', 50); 

remove_action('woocommerce_single_product_summary', 
     'woocommerce_template_single_add_to_cart', 30); 
add_action('woocommerce_before_single_product_summary', 
     'woocommerce_template_single_add_to_cart', 60); 

我想「選擇選項」選擇價格即前

add_action('woocommerce_before_single_product_summary', 
     'woocommerce_template_single_price', 50); 

它的優先級是50 所以,我對於加入優先級45

add_action('woocommerce_before_single_product_summary', 
     'woocommerce_variable_add_to_cart', 45); 

但還是woocommerce_variable_add_to_cart正顯示出以下 woocommerce_template_single_priceenter image description here 在上面的圖片中,如果我有45-50-60,那麼60和50會出現在單行中,45以上的是50,這是我的要求。

回答

1

我試過你的代碼,但它在這裏打破了我的頁面結構。

然後最終它讓我通過鉤子進行研究,並嘗試了一些導致此代碼的排列和組合。

remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10); 
add_action('woocommerce_single_variation', 'woocommerce_template_single_price', 19); 

希望對你有用。這裏沒有添加任何條件邏輯來限制它應用於其他類型的產品(我認爲你可以很好地處理)。

enter image description here

+0

是的,這解決了這個問題,對不起,遲交回復。 –

+0

最終改進代碼 https://jsfiddle.net/wasim717/08dj7ey5/ –