Итак, вот в чем дело, когда я пишу этот код в файле mytheme / functions.php
//this code for adding field in product backend
// Display Fields
add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields1');
// Save Fields
add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
function woocommerce_product_custom_fields1()
{
global $woocommerce, $post;
echo '<div class="product_custom_field">';
// Custom Product Text Field
woocommerce_wp_text_input(array(
'id' => '_custom_product_text_field',
'placeholder' => 'Custom Product Text Field',
'label' => __('Zoom Meeting Url ', 'woocommerce'),
'desc_tip' => 'true'
));
//Custom Product Number Field
woocommerce_wp_text_input(array(
'id' => '_custom_product_number_field',
'placeholder' => 'Custom Product Text Field',
'label' => __('Meeting ID', 'woocommerce'),
'type' => 'text',
'custom_attributes' => array(
// 'step' => 'any',
// 'min' => '0'
)
));
//Custom Product Textarea
woocommerce_wp_textarea_input(array(
'id' => '_custom_product_textarea',
'placeholder' => 'Custom Product Text',
'label' => __('Password', 'woocommerce')
));
echo '</div>';
}
function woocommerce_product_custom_fields_save($post_id)
{
// Custom Product Text Field
$woocommerce_custom_product_text_field = $_POST['_custom_product_text_field'];
if (!empty($woocommerce_custom_product_text_field))
update_post_meta($post_id, '_custom_product_text_field', esc_attr($woocommerce_custom_product_text_field));
// Custom Product Number Field
$woocommerce_custom_product_number_field = $_POST['_custom_product_number_field'];
if (!empty($woocommerce_custom_product_number_field))
update_post_meta($post_id, '_custom_product_number_field', esc_attr($woocommerce_custom_product_number_field));
// Custom Product Textarea Field
$woocommerce_custom_procut_textarea = $_POST['_custom_product_textarea'];
if (!empty($woocommerce_custom_procut_textarea))
update_post_meta($post_id, '_custom_product_textarea', esc_html($woocommerce_custom_procut_textarea));
}
add_action( 'woocommerce_email_after_order_table', 'wdm_add_shipping_method_to_order_email', 10, 2 );
function wdm_add_shipping_method_to_order_email( $order, $is_admin_email ) {
echo '<h4>Zoom Meeting Details</h4>';
$order_id = $order->get_id();
$order = wc_get_order( $order_id ); //returns WC_Order if valid order
$items = $order->get_items(); //returns an array of WC_Order_item or a child class (i.e. WC_Order_Item_Product)
foreach( $items as $item ) {
$type = $item->get_type();
$product_id = $item->get_product_id();
echo "<p>" . get_the_title($product_id) . "</p>";
echo "<p><strong>Zoom Meeting Url:</strong>" . get_post_meta($product_id, '_custom_product_text_field', true) . "</p>";
echo "<p><strong>Meeting ID:</strong>" . get_post_meta($product_id, '_custom_product_number_field', true) . "</p>";
echo "<p><strong>Password:</strong>" . get_post_meta($product_id, '_custom_product_textarea', true) . "</p>";
//more code
}
}
echo get_post_meta($id, '_custom_product_text_field', true);
echo get_post_meta($id, '_custom_product_number_field', true);
echo get_post_meta($id, '_custom_product_textarea', true);
он работает только в бэкэнде (страница редактирования продукта), он сохраняет переменные, но не отображается ни в мета, ни до - или - после кнопки добавления на карту я не смог найти решение для этого
Я попробовал эхо, но все равно безрезультатно
так я думал, что я был моей темой? нет, я установил wordpress на другие vps, у меня до сих пор не отображается текстовое поле-текст-ничего
если вы знаете проблему, пожалуйста, будьте добры и скажите мне, что я делаю не так! Благодарность