这个论坛过去给了我很大的帮助。
我还有一个疑问。
我希望添加一个联系表单,使其仅显示在 WooCommerce 类别页面的内容下 - 而不是显示在产品页面中。我使用以下代码来显示表单:
add_action( 'woocommerce_after_main_content', function(){
// Title
$header = "<br><b>Contact Us</b><br>";
// Message
$text = "<p>Please do not hesitate to contact us with queries you may have</p><br>";
// WPForms shortcode
$wpforms_shortcode = do_shortcode('[wpforms id="1385"]');
// Output combined message and form
echo '
' . $header .'
' . $text .'
' . $wpforms_shortcode .'
';
}, 9 );
但是,使用上面的代码也会使表单出现在产品页面的底部(链接) - 这里并不奇怪。
如何防止表单出现在产品页面底部?
感谢任何帮助或指导。
我添加了代码,正如预期的那样,在所有商店页面的底部看到了联系表格。我需要表单仅出现在类别页面中。
要仅在产品类别档案(页面)中显示代码输出,请使用以下命令:
add_action( 'woocommerce_after_main_content', 'display_product_category_contact_us_form', 9 );
function display_product_category_contact_us_form(){
if ( is_product_category() ) {
echo '<br>
<b>'.__('Contact Us', 'woocommerce').'</b><br>
<p>'.__('Please do not hesitate to contact us with queries you may have', 'woocommerce').'</p><br>
'.do_shortcode('[wpforms id="1385"]');
}
}
代码位于子主题的functions.php 文件中(或插件中)。已测试并有效。