Skip to content

Instantly share code, notes, and snippets.

View rynaldos-zz's full-sized avatar

Rynaldo rynaldos-zz

View GitHub Profile
@rynaldos-zz
rynaldos-zz / wc-no-po-box-shipping.php
Created October 12, 2017 13:11
[WooCommerce 3.0+] Preventing PO box shipping
add_action('woocommerce_after_checkout_validation', 'deny_pobox_postcode');
function deny_pobox_postcode( $posted ) {
global $woocommerce;
$address = ( isset( $posted['shipping_address_1'] ) ) ? $posted['shipping_address_1'] : $posted['billing_address_1'];
$postcode = ( isset( $posted['shipping_postcode'] ) ) ? $posted['shipping_postcode'] : $posted['billing_postcode'];
$replace = array(" ", ".", ",");
$address = strtolower( str_replace( $replace, '', $address ) );
@rynaldos-zz
rynaldos-zz / wc-goback-single-page.php
Last active March 20, 2021 02:37
[WooCommerce 3.0] Add "go back" button on single product page
add_action( 'woocommerce_after_add_to_cart_button', 'my_function_sample', 10 );
function my_function_sample() {
global $product;
echo ' <button type="button" onclick="history.back();"> Go back </button> ';
}
// Did this help? Donate me some BTC: 1BEsm8VMkYhSFJ92cvUYwxCtsfsB2rBfiG
@rynaldos-zz
rynaldos-zz / wc-upsells-increase.php
Last active March 20, 2021 02:38
[WooCommerce 3.0] Change number of upsells on single products
add_filter( 'woocommerce_output_related_products_args', 'wc_change_number_related_products' );
function wc_change_number_related_products( $args ) {
$args['posts_per_page'] = 1;
$args['columns'] = 4; //change number of upsells here
return $args;
}
@rynaldos-zz
rynaldos-zz / wc-min-pass-chars-req.php
Last active October 31, 2020 12:24
[WooCommerce 3.0] Require minimum password length for account registration, password update, and password resets
add_action('woocommerce_process_registration_errors', 'validatePasswordReg', 10, 2 );
function validatePasswordReg( $errors, $user ) {
// change value here to set minimum required password chars
if(strlen($_POST['password']) < 15 ) {
$errors->add( 'woocommerce_password_error', __( 'Password must be at least 15 characters long.' ) );
}
// adding ability to set maximum allowed password chars -- uncomment the following two (2) lines to enable that
//elseif (strlen($_POST['password']) > 16 )
//$errors->add( 'woocommerce_password_error', __( 'Password must be shorter than 16 characters.' ) );
@rynaldos-zz
rynaldos-zz / wc-placeholder-image-new.php
Last active July 2, 2020 05:22
[WooCommerce 3.0] Change placeholder image
add_action( 'init', 'custom_fix_thumbnail' );
function custom_fix_thumbnail() {
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
function custom_woocommerce_placeholder_img_src( $src ) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit( $upload_dir['baseurl'] );
$src = $uploads . '/2012/07/thumb1.jpg';
@rynaldos-zz
rynaldos-zz / wc-sf-footer-crds.php
Created August 7, 2017 05:45
[WooCommerce 3.0+] Remove Storefront footer credits
@rynaldos-zz
rynaldos-zz / wc-dcc-php
Last active July 2, 2020 05:22
[WooCommerce 3.0+] Change the default state and country on the checkout
add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_billing_state', 'change_default_checkout_state' );
function change_default_checkout_country() {
return 'XX'; // country code
}
function change_default_checkout_state() {
return 'XX'; // state code
}
@rynaldos-zz
rynaldos-zz / woocommerce-bookings-styles.css
Last active August 4, 2017 05:48 — forked from mikeyarce/woocommerce-bookings-styles.css
Bookings Datepicker Color Styles
/*
Modify the color styles of the WooCommerce Bookings datepicker calendar.
Add any/all of these styles to your theme's custom CSS, but be sure to change
the color hex codes to your choice. They're all black here.
*/
/* Month header background color */
#wc-bookings-booking-form .wc-bookings-date-picker .ui-datepicker-header {
background-color: #000000;
}
@rynaldos-zz
rynaldos-zz / wc-oip.php
Created August 3, 2017 10:34
[WooCommerce 3.0+] remove product links from order review page
add_filter( 'woocommerce_order_item_permalink', '__return_false' );
@rynaldos-zz
rynaldos-zz / wc-mya-cm.php
Created August 3, 2017 08:38
[WooCommerce 3.0] Custom my-account message / notice for logged out users
add_action( 'woocommerce_after_customer_login_form', 'wc_myacc_message' );
function wc_myacc_message() {
if ( get_option( 'woocommerce_enable_myaccount_registration' ) == 'yes' ) {
?>
<div class="woocommerce-info">
<p><?php _e( 'your custom message goes here' ); ?></p>
</div>
<?php
}
}