ACF field for just 1 product
-
I have code that shows my ACF on all product pages, billing details and sends with email order. I only want the ACF field to show on 1 product (which is product ID 2412′
/* Add the field to the checkout */
add_action( ‘woocommerce_after_checkout_billing_form’, ‘add_user_field_to_checkout’ );function add_user_field_to_checkout( $checkout ) {
$current_user = wp_get_current_user();
$saved_url = $current_user->front_door_key;woocommerce_form_field( ‘front_door_key’, array(
‘type’ => ‘text’,
‘class’ => array(‘user_url form-row-wide’),
‘label’ => __(‘Front Door Key Code’),
‘placeholder’ => __(‘Key Code’),
‘required’ => true
),
$saved_url );}
add_action( ‘woocommerce_before_add_to_cart_button’, ‘add_user_field_to_checkout’ );function woocommerce_before_add_to_cart_button( $checkout ) {
$current_user = wp_get_current_user();
$saved_url = $current_user->front_door_key;woocommerce_form_field( ‘front_door_key’, array(
‘type’ => ‘text’,
‘class’ => array(‘user_url form-row-wide’),
‘label’ => __(‘Front Door Key Code’),
‘placeholder’ => __(‘Key code ‘),
‘required’ => true
),
$saved_url );}
/* Add the field to the order */
add_action( ‘woocommerce_email_order_meta’, ‘add_user_field_to_order’ );function add_user_field_to_order( $order ) {
$current_user = wp_get_current_user();
$saved_url = $current_user->front_door_key;woocommerce_form_field( ‘front_door_key’, array(
‘type’ => ‘text’,
‘class’ => array(‘user_url form-row-wide’),
‘label’ => __(‘Front Door Key Code’),
‘placeholder’ => __(‘Key Code’),
‘required’ => true
),
$saved_url );}
- The topic ‘ACF field for just 1 product’ is closed to new replies.