Skip to content

Instantly share code, notes, and snippets.

Hien D. Nguyen hiendnguyen

Block or report user

Report or block hiendnguyen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hiendnguyen
hiendnguyen / registration-form.php
Created Mar 7, 2017
WooCommerce Registration Custom Fields Utilities
View registration-form.php
<?php
/*** Change default login url to WooCommerce My Account ***/
function my_login_page( $login_url, $redirect ) {
$myaccount_url = get_permalink(wc_get_page_id('myaccount'));
return $redirect == '' ? $myaccount_url : $myaccount_url . '?redirect_to=' . $redirect;
}
add_filter( 'login_url', 'my_login_page', 10, 2 );
/*** We don't want "account page" displays after login by default. We want to display homepage instead ***/
@hiendnguyen
hiendnguyen / registration-form.php
Last active Mar 7, 2017
WooCommerce Registration Custom Fields Saving
View registration-form.php
<?php
/** Save the extra register fields. */
function wooc_save_extra_register_fields( $customer_id ) {
if ( isset( $_POST['billing_first_name'] ) ) {
// WordPress default first name field.
update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
// WooCommerce billing first name.
update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
}
@hiendnguyen
hiendnguyen / registration-form.php
Last active Mar 7, 2017
WooCommerce Registration Custom Fields Validation
View registration-form.php
<?php
/** Validate the extra register fields. */
function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
$validation_errors->add( 'billing_first_name_error', __( 'What\'s your first name?', 'woocommerce' ) );
}
if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
$validation_errors->add( 'billing_last_name_error', __( 'What\'s your last name?', 'woocommerce' ) );
@hiendnguyen
hiendnguyen / registration-form.php
Last active Mar 7, 2017
WooCommerce Registration Custom Fields Frontend
View registration-form.php
function wooc_extra_register_fields() {
?>
<p class="form-row form-row-first">
<label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
</p>
<p class="form-row form-row-last">
<label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?> <span class="required">*</span></label>
@hiendnguyen
hiendnguyen / woocommerce-registration-custom-fields.php
Created Mar 7, 2017
WooCommerce Registration Custom Fields
View woocommerce-registration-custom-fields.php
<?php
/* Plugin Name: WooCommerce Registration Custom Fields
* Plugin URI: https://vndeveloper.com
* Description: Add Fist Name, Last Name, Phone, Company, Role fields as well as Privacy Policy and Terms of Use links into WooCommerce Registration form.
* Version: 1.0.0
* Author: VNDeveloper
* Author URI: https://vndeveloper.com
* Requires at least: 4.1
* Tested up to: 4.7
* Text Domain: vndev-wooc-signup
@hiendnguyen
hiendnguyen / vndeveloper.conf
Last active Mar 31, 2017
NGINX Server Block File
View vndeveloper.conf
server {
listen 80;
server_name vndeveloper.com www.vndeveloper.com;
root /var/www/vndeveloper.com/html;
index index.html index.htm index.php;
location / {
You can’t perform that action at this time.