2012-09-09 25 views
2

我遇到了WooCommerce的问题,试图返回特定类“售罄”的商品已售罄。我正在使用一个返回div而不是经典下拉的插件。所以你可以选择[S] [M] [L] [XL]等。看看我的意思 - http://www.shultzilla.com/product/tees/greater-than/ -woocommerce - 试图返回缺货类

所以我有一个div,我想添加这个类。我会对它进行设计,以便您不能点击它,并且会使它在产品售罄时无法点击。

这是我正在做的,但它似乎并没有回报任何东西。甚至没有错误:

public function is_in_stock() { 
     if ($this->managing_stock()) : 
      if (! $this->backorders_allowed()) : 
       if ($this->get_total_stock() < 1) : 
        return false; 
       else : 
        if ($this->stock_status == 'instock') return true; 
        return false; 
       endif; 
      else : 
       return true; 
      endif; 
     endif; 
     if ($this->stock_status == 'instock') return true; 
     return false; 
    } 

function is_sold_out() { 
     if ($product->is_in_stock()) { 
      $soldOutClass = 'in-stock'; 
     } else { 
      $soldOutClass = 'sold-out'; 
     } 
    } 

public function get_output($placeholder = true, $placeholder_src = 'default') { 
     global $woocommerce; 


     $out = '<div class="select-option swatch-wrapper '.$soldOutStatus .'" data-value="' . $this->term_slug . '" ' . ($this->selected ? 'data-default="true"' : '') . '>'; 

     if ($this->type == 'photo' || $this->type == 'image') { 

      $out .= '<a href="#" style="width:' . $this->width . 'px;height:' . $this->height . 'px;" title="' . $this->term_label . '">'; 
      $out .= '<img src="' . $this->thumbnail_src . '" alt="Thumbnail" class="wp-post-image swatch-photo' . $this->meta_key() . '" width="' . $this->width . '" height="' . $this->height . '"/>'; 
      $out .= '</a>'; 
     } elseif ($this->type == 'color') { 
      $out .= '<a href="#" style="text-indent:-9999px;width:' . $this->width . 'px;height:' . $this->height . 'px;background-color:' . $this->color . ';" title="' . $this->term_label . '">' . $this->term_label . '</a>'; 
     } elseif ($placeholder) { 
      if ($placeholder_src == 'default') { 
       $src = $woocommerce->plugin_url() . '/assets/images/placeholder.png'; 
      } else { 
       $src = $placeholder_src; 
      } 

      $out .= '<a href="#" style="width:' . $this->width . 'px;height:' . $this->height . 'px;" title="' . $this->term_label . '">'; 
      $out .= '<img src="' . $src . '" alt="Thumbnail" class="wp-post-image swatch-photo' . $this->meta_key() . '" width="' . $this->width . '" height="' . $this->height . '"/>'; 
      $out .= '</a>'; 
     } else { 
      return ''; 
     } 

     $out .= '</div>'; 

     return $out; 
    }' 

因此,正如你所看到的,我正在尝试不工作。我不确定我做错了什么。

+0

@jvdberg,你是如何设法修复格式的?我无法让它工作。 –

回答

3

试试这个功能在你的模板PHP:

function is_out_of_stock() { 
    global $post; 
    $post_id = $post->ID; 
    $stock_status = get_post_meta($post_id, '_stock_status',true) == 'outofstock'; 
} 

然后你可以这样做:

<img class="<?php echo is_out_of_stock()? 'outofstock':''; ?>" src="..."></img> 
+0

嘿马克。感谢您的回复。我会研究这个,看看我们能做些什么。感谢您的输入! –

0

创建你的主题目录下名为/woocommerce一个文件夹,然后内创建另一个文件夹这叫做/loop,最后把add-to-cart.php文件从这个插件里面,修改第17行到: ..class="out-of-stock mycustomclasshere"><?php echo apply_filters('out_of_stock_add_to_cart_text',__('Out of Stock','woocommerce'));?>..

mycustomclasshere显然是你自己的CSS样式输出。