WooCommerce中的某些产品的“售罄”更改
问题描述:
我想要做的是更改标准的WooCommerce售罄消息,并为其添加一些内容,仅用于两种类型的产品。WooCommerce中的某些产品的“售罄”更改
我决定尝试通过改变出现在p元素中的文本来尝试使用JavaScript。我首先做一个窗口url检查,看看我们是否在正确的页面上,如果我们是,那么确保文本不只是说“UITVERKOCHT”,而是“UITVERKOCHT”(通过contactformulier的neem contact op,levertijd 2 werkdagen) “。
UITVERKOCHT显示产品售罄的时间。但就这两种产品而言,我想在UITVERKOCHT之后添加额外的消息。所以这是我到目前为止所尝试的。
if(window.location.href.indexOf("prikkabel-50-meter") > -1 || window.location.href.indexOf("prikkabel-100-meter") > -1){
jQuery("#product-5666 > div.single-product-wrapper > div.summary.entry-summary > form > div > div.woocommerce-variation.single_variation > div.woocommerce-variation-availability > p").change(function() {
console.log('a change occured');
});
}
任何想法还有什么我能试试吗?
答
你可以尝试woocommerce_get_availability
过滤器:
在你的主题functions.php
:
add_filter('woocommerce_get_availability', 'custom_availability', 5, 2);
function custom_availability($availability, $_product) {
// If the product is out of stock and the product id = 5666
if (! $_product->is_in_stock() && $_product->id === 5666) {
$availability['availability'] = __('[your custom text here]', 'woocommerce');
}
return $availability;
}
这将适用于上述过滤如果产品缺货和产品ID是 。