This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('woocommerce_validate_postcode','woo_validate_belgium_postcode',10,3); | |
function woo_validate_belgium_postcode($valid, $postcode, $country){ | |
if($country=="BE") | |
$valid = (bool) preg_match( '/^([0-9]{4})$/', $postcode ); | |
// Checks your postcode to seee if it matches belgium (4 digits). If not, it will reject validation. | |
return $valid; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This snippet helps you add custom images (like "Secure Checkout") to single product pages. You can add it to your site at the bottom of your theme's `functions.php` file, or by using a Code Snippets Plugin: https://wordpress.org/plugins/code-snippets/ | |
The end result would look like this: https://d.pr/i/nUk1Bm | |
*/ | |
function woo_add_security_image() { | |
echo '<img src="https://example.com/security-image-url.jpg" />'; // Replace the URL here with the URL of your image. | |
/* Remove the `//` Comments and update the URL(s) below if you would like to add multiple images to your single product page */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 ); | |
function remove_add_to_cart_buttons() { | |
/*Removes add to cart buttons from shop, category, and home pages */ | |
if( is_product_category() || is_shop() || is_front_page()) { | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ); | |
} | |
/*Removes add to cart buttons from related products section */ | |
global $woocommerce_loop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('woocommerce_order_status_changed', 'wc_auto_complete_by_payment_method'); | |
function wc_auto_complete_by_payment_method($order_id) | |
{ | |
if ( ! $order_id ) { | |
return; | |
} | |
global $product; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Adds then moves Apple Pay button on the checkout page. | |
*/ | |
add_filter( 'wc_stripe_show_payment_request_on_checkout', '__return_true' ); | |
remove_action( 'woocommerce_checkout_before_customer_details', array( WC_Stripe_Payment_Request::instance(), 'display_payment_request_button_html' ), 1 ); | |
remove_action( 'woocommerce_checkout_before_customer_details', array( WC_Stripe_Payment_Request::instance(), 'display_payment_request_button_separator_html' ), 2 ); | |
add_action( 'woocommerce_after_checkout_form', array( WC_Stripe_Payment_Request::instance(), 'display_payment_request_button_html' ), 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_add_to_cart_validation', 'wc_limit_one_per_order', 10, 2 ); | |
function wc_limit_one_per_order( $passed_validation, $product_id ) { | |
$terms = wp_get_post_terms( $product_id, 'product_cat' ); | |
foreach ( $terms as $term ) $categories[] = $term->slug; | |
if ( in_array( 'clothes', $categories ) ) { // 'clothes' is the defined product category. Change this value to the slug of your choice. | |
return $passed_validation; | |
} | |
/* if ( 55 !== $product_id ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. | |
*/ | |
NewerOlder