请帮助!! 我有一个程序员,为我添加了一个afc插件的海关领域。唯一的问题是后端产品页面上显示的是acf部分的海关字段,而不是woocommerece产品数据板。他们就是我需要田地的地方。
所以这是我必须在function.php上的woocommerce常规选项卡上添加字段的代码,它出现在我想要的地方
add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');
// Save Fields
add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
function woocommerce_product_custom_fields()
{
global $woocommerce, $post;
echo '<div class="product_custom_field">';
//Custom Product Number Field
woocommerce_wp_text_input(
array(
'id' => 'offer_a_commission_percentage_to_instar_model_on_each_sale',
'placeholder' => '20',
'label' => __('Offer a commission percentage to InStar model on each sale', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'default_value' => 20,
'append' => '%',
'step' => '',
'min' => '20',
)
)
);
//Custom Product Number Field
woocommerce_wp_text_input(
array(
'id' => 'offer_additional_award_points_to_your_model_for_each_sale',
'placeholder' => '1',
'label' => __('Offer additional award points to your model for each sale', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'default_value' => 1,
'step' => '',
'min' => '1'
)
)
);
程序员在do_action( 'woocommerce_single_product_summary' );
下的content-single-product.php的前端添加此代码(这是其中我想要前端的字段):
if ( get_field('offer_a_commission_percentage_to_instar_model_on_each_sale') ) {
$number = get_field('offer_a_commission_percentage_to_instar_model_on_each_sale');
echo '<div>earn '. ($number / 2) .'% commission on each sale</div>';
}
if ( get_field('offer_additional_award_points_to_your_model_for_each_sale') ) {
echo '<div>earn '. get_field('offer_additional_award_points_to_your_model_for_each_sale') .' award points from each sale for your next campaigns</div>';
} ?>
为什么我希望字段显示在前端
从我在网上缝制的内容我还需要在数据库中保存数据 有人可以根据我在这里展示的代码向我发送带有指令的代码吗?也更清楚我不想使用acf插件这是我遵循的代码并试图修改为程序员与acf一起使用的代码
// Display Fields
add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');
// Save Fields
add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
function woocommerce_product_custom_fields()
{
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' => __('Custom Product Text Field', 'woocommerce'),
'desc_tip' => 'true'
)
);
//Custom Product Number Field
woocommerce_wp_text_input(
array(
'id' => '_custom_product_number_field',
'placeholder' => 'Custom Product Number Field',
'label' => __('Custom Product Number Field', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
)
)
);
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));
}
<?php while (have_posts()) : the_post(); ?>
<?php wc_get_template_part('content', 'single-product'); ?>
<?php
// Display the value of custom product text field
echo get_post_meta($post->ID, '_custom_product_text_field', true);
// Display the value of custom product number field
echo get_post_meta(get_the_ID(), '_custom_product_number_field', true);
// Display the value of custom product text area
echo get_post_meta(get_the_ID(), '_custom_product_textarea', true);
?>
<?php endwhile; // end of the loop. ?>
enter code here