Code Monkey home page Code Monkey logo

woocommerce's People

Watchers

 avatar  avatar

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.