woocommerce's People
woocommerce's Issues
Add the field to the checkout
/**
- Add the field to the checkout
**/
add_action('woocommerce_before_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>'.__('Como nos conheceu?').'</h3>';
woocommerce_form_field( 'my_field_name', array(
'type' => 'select',
'class' => array('my-field-class form-row-wide'),
'required' => true,
'label' => __('Escolha uma opção'),
'placeholder' => __('Enter something'),
'options' => array(
'' => __(''),
'pelo Google' => __('OPÇÃO 01', 'woocommerce' ),
'pelo Facebook' => __('OPÇÃO 02', 'woocommerce' ),
'pelo blog Site da Mamãe' => __('OPÇÃO 03', 'woocommerce' ),
'por indicação' => __('OPÇÃO 04', 'woocommerce' )
)
), $checkout->get_value( 'my_field_name' ));
echo '</div>';
}
/**
- Process the checkout
**/
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
global $woocommerce;
// Check if set, if its not set add an error.
if (!$_POST['my_field_name'])
$woocommerce->add_error( __('Please enter something into this new shiny field.') );
}
/**
- Update the order meta with field value
**/
add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ($_POST['my_field_name']) update_post_meta( $order_id, 'Como nos conheceu?', esc_attr($_POST['my_field_name']));
}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.