WordPress大师您好,
我有一个WooCommerce问题需要帮助。我更多的是一个前端开发人员斜杠设计师,到目前为止,我试图解决这个问题的尝试都没有成功。
What I\'m trying to do: 每当产品缺货时,我都想在下面显示一条定制的缺货消息(完成)和一张联系表单(需要帮助)。
我使用联系人表格7,并有一个通常插入的快捷码。我已经知道如何用echo do_shortcode(\'[name_of_shortcode]\');
我不知道如何使它只出现在缺货的产品上。
Here\'s the custom code I currently use in my child-theme\'s function.php file:
add_filter(\'woocommerce_get_availability\', \'availability_filter_func\');
function availability_filter_func($availability)
{
$availability[\'availability\'] = str_ireplace(\'Out of stock\', \'This class is not currently available at a scheduled time, but is instead being scheduled in response to customer interest. If you are interested in taking this class, please provide your contact information and we will reach out to with dates that are currently under consideration.\', $availability[\'availability\']);
return $availability;
}
如您所见,我可以更改定制的缺货消息,但我不知道如何在消息后调用短代码。
WordPress和WooCommerce大师,我该怎么办?
感谢您的帮助,感谢您抽出时间来教育我!
蒂娜
最合适的回答,由SO网友:Pascal Knecht 整理而成
您需要使用WooCommerce提供的挂钩。我会像下面这样尝试(未经测试):
add_action(\'woocommerce_single_product_summary\', \'add_contact_form\', 20);
function add_contact_form() {
global $product;
if(!$product->is_in_stock( )) {
echo do_shortcode(\'[name_of_shortcode]\');
}
}