我目前正在創建一個小部件,以在使用WooCommerce的WordPress網站上顯示註冊表單。目前,我只有3個基本字段,分別是電子郵件,密碼,重複密碼。我期待添加更多WooCommerce字段,但在跳到下一步之前要解決該問題。WooCommerce註冊簡碼 - 錯誤消息問題
我有一些問題的消息輸出(密碼錯誤,帳戶已存在等)。
我在網上搜索過,沒有爲WooCommerce註冊建立的短碼,它們的註冊頁面旁邊。所以我繼續創建一個帶有模板部分的簡碼。
function custom_register_shortcode($atts, $content){
global $woocommerce;
$form = load_template_part('framework/views/register-form');
return $form;
}
add_shortcode('register', 'custom_register_shortcode');
這是一個片段我用它來獲得一個變量中模板的一部分,因爲默認功能將「回聲」的內容,而不是「迴歸」了。
function load_template_part($template_name, $part_name=null) {
ob_start();
get_template_part($template_name, $part_name);
$var = ob_get_contents();
ob_end_clean();
return $var;
}
所以,問題是,當我叫woocommerce_show_messages
或$woocommerce->show_messages();
從我的模板的一部分,沒有什麼是展示,或者如果它是,它顯示在頁面的頂部。
我曾嘗試把我的短代碼函數內部調用:
function custom_register_shortcode($atts, $content){
global $woocommerce;
$woocommerce->show_messages();
$form = load_template_part('framework/views/register-form');
return $form;
}
add_shortcode('register', 'custom_register_shortcode');
這樣做,<head>
標籤內的信息輸出,這不是我想要的。
我試圖用ob_start()
,ob_get_contents()
和ob_clean()
做同樣的把戲,但沒有任何顯示。該變量將是空的。
我還沒有嘗試到woocommerce_show_messages
鉤到核心的行動鋸:
add_action('woocommerce_before_shop_loop', 'woocommerce_show_messages', 10);
類似:
add_action('before_registration_form', 'woocommerce_show_messages');
我加入這在我的模板 - 部分:
<?php do_action('before_registration_form'); ?>
但我仍然無法設法得到框內的錯誤信息。它將始終插入到<head>
我將在完成所有工作時共享最終解決方案。
感謝您的時間,
朱利安