Skip to content

Instantly share code, notes, and snippets.

@brunoalvarenga
brunoalvarenga / jquery.wc-custom.js
Created September 30, 2016 20:33 — forked from SirDarcanos/jquery.wc-custom.js
woocommerce ajax load billing address
jQuery(document).ready(function ( $ ) {
$( 'button.load_customer_billing' ).off( 'click' );
$( 'button.load_customer_billing' ).on( 'click', function() {
if ( window.confirm( woocommerce_admin_meta_boxes.load_billing ) ) {
// Get user ID to load data for
var user_id = $( '#customer_user' ).val();
if ( ! user_id ) {
window.alert( woocommerce_admin_meta_boxes.no_customer_selected );
function wcs_redirect_product_based ( $order_id ){
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
$_product = wc_get_product( $item['product_id'] );
// Add whatever product id you want below here
if ( $item['product_id'] == 70 ) {
// change below to the URL that you want to send your customer to
wp_redirect('http://www.yoururl.com/your-thank-you-page');
}
/**
* Register term fields
*/
add_action( 'init', 'register_vendor_custom_fields' );
function register_vendor_custom_fields() {
add_action( WC_PRODUCT_VENDORS_TAXONOMY . '_add_form_fields', 'add_vendor_custom_fields' );
add_action( WC_PRODUCT_VENDORS_TAXONOMY . '_edit_form_fields', 'edit_vendor_custom_fields', 10 );
add_action( 'edited_' . WC_PRODUCT_VENDORS_TAXONOMY, 'save_vendor_custom_fields' );
add_action( 'created_' . WC_PRODUCT_VENDORS_TAXONOMY, 'save_vendor_custom_fields' );
}
remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
add_action( 'woocommerce_proceed_to_checkout', 'change_url_to_checkout', 20 );
function change_url_to_checkout() {
$cart = WC()->cart->get_cart();
$url = '';
foreach ( $cart as $item ) {
if ( $item['product_id'] === 70 ) {
$url = 'put_your_extra_page_url_here';
break;
/**
* Redirect to a specific page when clicking on Continue Shopping in the single product page
*
* @return void
*/
function wc_custom_redirect_continue_shopping( $message ) {
if ( strpos( $message, __( 'View Cart', 'woocommerce' ) ) !== false ) {
$message = str_replace( esc_url( wc_get_page_permalink( 'cart' ) ), esc_url( wc_get_page_permalink( 'shop' ) ), $message );
$message = str_replace( __( 'View Cart', 'woocommerce' ), esc_html__( 'Continue Shopping', 'woocommerce' ), $message );
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
@brunoalvarenga
brunoalvarenga / seller-registration-form.php
Created October 4, 2016 21:40 — forked from mahbubme/seller-registration-form.php
Remove first-name and last-name compulsory option from Dokan seller registration form. Plugin File location (templates/global/seller-registration-form.php)
<?php
/**
* Dokan Seller registration form
*
* @since 2.4
*
* @package dokan
*/
?>
@brunoalvarenga
brunoalvarenga / functions.php
Created October 4, 2016 21:40 — forked from mahbubme/functions.php
Remove Dokan seller registration form default validation and add new validation.
// remove the filter
remove_filter( 'woocommerce_process_registration_errors', 'dokan_seller_registration_errors' );
remove_filter( 'registration_errors', 'dokan_seller_registration_errors' );
// New registration form erros handling
function dokan_update_seller_registration_errors( $error ) {
$allowed_roles = apply_filters( 'dokan_register_user_role', array( 'customer', 'seller' ) );
// is the role name allowed or user is trying to manipulate?
if ( isset( $_POST['role'] ) && !in_array( $_POST['role'], $allowed_roles ) ) {
<?php
/*
* Paste this code in the functions.php
*/
add_action( 'woocommerce_after_add_to_cart_button', 'seller_link_in_product_page');
function seller_link_in_product_page() {
<?php
/**
* Add and update custom field through Action Hook in registration form. Paste this code in the functions.php . You should create action hook "wpuf_registration_form_hook" in the registration field.
*
* @param int $form_id
* @param null|int $user_id
* @param array $form_settings
*/
function render_registration_form_hook( $form_id, $user_id, $form_settings ) {