我遇到了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;
}'
因此,正如你所看到的,我正在尝试不工作。我不确定我做错了什么。
@jvdberg,你是如何设法修复格式的?我无法让它工作。 –