如何在WooCommerce中显示缺货产品的联系人表单?

时间:2017-07-31 作者:vervex

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大师,我该怎么办?

感谢您的帮助,感谢您抽出时间来教育我!

蒂娜

1 个回复
最合适的回答,由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]\');
    }
}

结束

相关推荐

如何阻止对自定义主题的header.php的重复黑客攻击?

注意到网站根文件夹上有一些不需要的文件,并将其删除。我找到了那个标题。php文件包含一些恶意代码,这些代码只能重定向到移动浏览器上的垃圾邮件网站。当这些文件存在时。htaccess pretty permalinks不起作用。我已经更改了Cpanel、FTP密码。已删除以下列出的不需要的文件。已扫描所有文件和文件夹。在干净地安装wordpress和插件之后,会重复添加这些文件。服务器:使用Cpanel/FileZilla的共享主机/linux服务器文件传输如何阻止这些重复的攻击?恶意脚本列表。ssl。ph