I am working on a WordPress eCommerce website, where I am using the WooCommerce platform to power the Shopping features.
I have created a Custom Text Box, which appears on the Product Page. This text box allows site visitors to enter any text they would like to appear on their Product. To create this Custom Text Box, I have entered the following code into the functions.php
file:
<div>
<label class="product-custom-text-label" for="engrave_text"><?php _e( 'Engraving option:', 'woocommerce'); ?><br>
<input style="min-width:220px" type="text" class="product-counter" name="engrave_text" placeholder="<?php _e( 'Enter Your Custom Letters ...', 'woocommerce'); ?>" minlength="2" maxlength="3" />
</label>
</div>
As you can see, I have manually/statically entered the minlength="2" maxlength="3"
attributes. Rather than having to manually enter said attributes, I want to dynamically call the values from a Custom Field, within the WooCommerce Product Dashboard.
WooCommerce Product Dashboard: Custom Field
To create the Custom Field, within the WooCommerce Product Dashboard, I entered the below code into the functions.php
file:
function product_custom_lettering(){
echo '<div class="product_custom_field">';
woocommerce_wp_text_input(
array(
'id' => '_minimum_engrave_text_option',
'desc' => __('set custom minimum Lettering text field', 'woocommerce'),
'label' => __('Minimum Letters', 'woocommerce'),
'desc_tip' => 'true'
)
);
echo '</div>';
}
add_action('woocommerce_product_options_general_product_data', 'product_custom_lettering');
Is anyone aware of how this can be achieved?