Skip to content

Instantly share code, notes, and snippets.

@estebandelaf
Last active June 16, 2020 20:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save estebandelaf/acd77824a922de244f933f47403b4079 to your computer and use it in GitHub Desktop.
Save estebandelaf/acd77824a922de244f933f47403b4079 to your computer and use it in GitHub Desktop.
Snippet para solicitar datos de un DTE chileno en el checkout de WooCommerce
add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields');
function custom_override_checkout_fields($fields)
{
$fields['billing']['billing_documento'] = array(
'type' => 'select',
'label' => __('Documento', 'woocommerce'),
'options' => array(33=>'Factura', 39=>'Boleta'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true,
);
$fields['billing']['billing_rut'] = array(
'label' => __('RUT', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true,
);
$fields['billing']['billing_giro'] = array(
'label' => __('Giro', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true,
);
return $fields;
}
add_action('woocommerce_admin_order_data_after_shipping_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1);
function my_custom_checkout_field_display_admin_order_meta($order)
{
$documentos = [33=>'Factura', 39=>'Boleta'];
echo '<h3>Datos DTE</h3>';
echo '<p><strong>'.__('Documento').':</strong><br/>'.$documentos[get_post_meta($order->get_id(), '_billing_documento', true)].'</p>';
echo '<p><strong>'.__('RUT').':</strong><br/>'.get_post_meta($order->get_id(), '_billing_rut', true).'</p>';
echo '<p><strong>'.__('Giro').':</strong><br/>'.get_post_meta($order->get_id(), '_billing_giro', true).'</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment