Tambah Kolom checkbox di halaman checkout dengan mudah


To add a simple checkbox field to you checkout, add this to your functions.php:

<?php

/**
* Add checkbox field to the checkout
**/
add_action(‘woocommerce_after_order_notes’, ‘my_custom_checkout_field’);

function my_custom_checkout_field( $checkout ) {

echo ‘<div id=”my-new-field”><h3>’.__(‘My Checkbox: ‘).'</h3>’;

woocommerce_form_field( ‘my_checkbox’, array(
‘type’          => ‘checkbox’,
‘class’         => array(‘input-checkbox’),
‘label’         => __(‘I have read and agreed.’),
‘required’  => true,
), $checkout->get_value( ‘my_checkbox’ ));

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_checkbox’])
$woocommerce->add_error( __(‘Please agree to my checkbox.’) );
}

/**
* 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_checkbox’]) update_post_meta( $order_id, ‘My Checkbox’, esc_attr($_POST[‘my_checkbox’]));
}

?>

 

atau silahkan lihat scriptnya disini

Iklan

Satu Tanggapan

  1. oke, saya coba dulu bos skripnya ya. makasih

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: