我正在使用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