我正在使用WooCommerce功能的WordPress網站上工作。如何在WooCommerce產品頁面上創建自定義文本框?
我已經建立2個自定義字段,對於產品頁的後端內的產品數據中,使用以下代碼:
<?php
function theme_name_woocommerce_custom_fields() {
// Price Per Character
woocommerce_wp_text_input(
array(
'id' => '_character_price',
'label' => 'Price Per Character',
'description' => 'This is the amount a customer pays per letter entered.',
'desc_tip' => 'true',
'placeholder' => 'Enter Amount per Letter (Exclude the £)'
)
);
// Custom Text Box
woocommerce_wp_checkbox(
array(
'id' => '_custom_text_box',
'label' => 'Show Custom Text Box',
'description' => 'Select this box, if you would like a Custom Text Box to appear on the Product's page.',
'desc_tip' => 'true',
)
);
}
add_action('woocommerce_product_options_general_product_data', 'theme_name_woocommerce_custom_fields');
function save_theme_name_woocommerce_custom_field($post_id) {
if (! empty($_POST['_custom_text_field'])) {
update_post_meta($post_id, '_custom_text_field', esc_attr($_POST['_custom_text_field']));
}
}
add_action('woocommerce_process_product_meta', 'save_theme_name_woocommerce_custom_fields');
?>
在參考woocommerce_wp_checkbox
,我想創建一個功能,由此當此複選框被選中時,它會在相關產品的頁面上創建一個自定義文本框。這個自定義文本框然後可以被潛在客戶用來輸入他們想要打印到頁面的產品中的一段文本。
有人知道我需要輸入什麼額外的編碼,以達到上述目標嗎?
感謝您的回覆。這將如何在產品頁面上創建一個文本框,以便潛在客戶輸入他們自己的文本? – Craig
如果你看到單品/ add-to-cart/variable.php,你會在那裏找到表單標籤 - 同樣適用於simple.php。只需添加一個文本框 - 一個正常的html輸入控件。並添加您的自定義js以顯示/隱藏它 –
我怎樣才能設置它,以便當選擇複選框時,文本框出現? – Craig