Skip to content

Instantly share code, notes, and snippets.

@harishankerr
harishankerr / social-login-to-wp.php
Created November 28, 2016 07:50
Adds Social Login to WordPress login and registration pages
<?php
/**
* Add social login buttons to the WP login page and
* adjust the instructions text appropriately
*/
/**
* Adds login buttons to the wp-login.php pages
*/
function sv_wc_social_login_add_buttons_wplogin() {
<?php // only copy this line if needed
/**
* Remove the tracking code added by WooCommerce Google Analytics Pro
* - this is usefull if your theme or another plugin is adding the tracking code
* - and you wish to use that instead
*/
function sv_wc_google_analytics_pro_remove_tracking_code() {
// check if Google Analytics Pro is active
if ( ! function_exists( 'wc_google_analytics_pro' ) ) {
return;
<?php // only copy this line if needed
/**
* Filter the document table headers to add a product thumbnail header
*
* @param array $table_headers Table column headers
* @return array The updated table column headers
*/
function sv_wc_pip_document_table_headers_product_thumbnail( $table_headers ) {
$thumbnail_header = array( 'product_thumbnail' => 'Thumbnail' );
// add product thumnail column as the first column
//Code to increase the excerpt length in WordPress.
function custom_excerpt_length( $length ) {
return 100; // This is the number of words.
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
// Change Out of Stock Text
if ( ! $_product->is_in_stock() ) {
$availability['availability'] = __('Sold Out', 'woocommerce');
}
return $availability;
}
@harishankerr
harishankerr / remove-checkout-fields.php
Last active May 2, 2017 03:25
Remove Checkout Fields From WooCommerce Checkout
<?php // Use the PHP Tag only if needed
/*
Snippet to remove Company And Phone Fields From The Checkout Page In WooCommerce
---------------------------------------------------------------------------------
Please paste this code snippet at the bottom of the functions.php file in your theme, or use a Code Snippets Plugin (https://wordpress.org/plugins/code-snippets/)plugin to add this snippet.
*/
@harishankerr
harishankerr / add-handing-fee.php
Last active June 7, 2017 01:25
Add Handling Fee To Flat Rate Shipping Method
function wc_ninja_change_flat_rates_cost( $rates, $package ) {
// Make sure flat rate is available
if ( isset( $rates['flat_rate'] ) ) {
// Adds a $3 handling fee to the existing flat rate shipping method.
$rates['flat_rate']->cost += 3;
}
return $rates;
}
/**
* Customize user data for new users registered via WC Social Login
* Example: set a custom role other than "customer" on registration
*/
/**
* Add filters to adjust user data for each active Social Login provider
*/
function sv_wc_social_login_new_user_data_add_filters() {
if ( ! function_exists( 'wc_social_login' ) ) {
/*
This code snippet reorders the shipping methods in your WooCommerce website,
in an ascending order in terms of shipping costs.
Copy the content to your theme's functions.php file or use a custom code snippet plugin
like this one: https://github.com/woocommerce/theme-customisations to prevent the code
from being overwritten during theme updates.
*/
add_filter( 'woocommerce_package_rates' , 'reorder_shipping_methods', 10, 2 );
function reorder_shipping_methods( $rates, $package ) {
@harishankerr
harishankerr / mandatory-state-field.php
Created December 18, 2018 03:57
Make State Field Mandatory For WooCommerce
// Hook in
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_state_fields' );
// Our hooked in function - $state_fields is passed via the filter!
function custom_override_default_state_fields( $state_fields ) {
$state_fields['state']['required'] = true;
return $state_fields;
}