Skip to content

Instantly share code, notes, and snippets.

@cartimize
cartimize / Thank you page custom HTML block
Last active August 11, 2021 16:17
This is the code snippet for creating a custom HTML block in the Thank you page.
add_action( 'woocommerce_thankyou', 'cartimize_thank_you_custom_block_details', 100, 100000000000 );
function cartimize_thank_you_custom_block_details(){
?>
<section class="woocommerce-block">
<h2>Title goes here</h2>
<div>
Content goes here
</div>
add_filter( 'cartimize_get_billing_checkout_fields', 'cartimize_custom_brazil_add_additional_billing_fields' , 10000, 1 );
function cartimize_custom_brazil_add_additional_billing_fields( $fields ){
if ( !isset( $fields['billing_neighborhood'] ) ) {
return $fields;
}
unset( $fields['billing_neighborhood']['is_hidden'] );
unset( $fields['billing_neighborhood']['cartimize_optional_label'] );
@cartimize
cartimize / fullname.js
Last active January 11, 2022 09:19
Shipping and Billing full name Javascript and php validation
// Shipping full name validation
jQuery( document.body ).on( 'cartimize_shipping_full_name_validation', function(event, defaultResult, fieldValue){
//Add your custom code here. Return true or false else it will use default validation
//Example: Check fieldValue empty or not
if(fieldValue.length === 0 ){
return false;
}else{
return true;
}
@cartimize
cartimize / modify_form_field.php
Last active January 21, 2022 12:28
Here is the example for shipping and billing phone number validation. Add this custom code to your WordPress site
<?php
// Shipping filed validation
add_filter('cartimize_get_shipping_checkout_fields', 'cartimize_modify_shipping_checkout_fields_new', 100, 1);
function cartimize_modify_shipping_checkout_fields_new( $checkout_fields ){
if ( isset($checkout_fields['shipping_phone']) && $checkout_fields['shipping_phone']['required'] == true ) {
$checkout_fields['shipping_phone'] = $checkout_fields['shipping_phone'];
$checkout_fields['shipping_phone']['custom_attributes']['data-parsley-pattern'] = '([0-9]{10})';
}
@cartimize
cartimize / fullname_label_text.php
Created October 7, 2021 15:40
A filter function to change full name label
<?php
add_filter( 'cartimize_full_name_text_label', 'custom_cartimize_full_name_text_label' , 1000, 1 );
function custom_cartimize_full_name_text_label($text){
return 'First name';
}
@cartimize
cartimize / custom_address_1_parsley_custom_validator.php
Last active October 9, 2021 04:37
How to activate the custom JS validator for the following fields (billing_address_1, shipping_address_1)
<?php
add_filter('cartimize_get_billing_checkout_fields', 'cartimize_custom_get_billing_checkout_fields', 10, 1);
function cartimize_custom_get_billing_checkout_fields( $value ){
$value['billing_address_1']['parsley_custom_validator']= true;
return $value;
}
add_filter('cartimize_get_shipping_checkout_fields', 'cartimize_custom_get_shipping_checkout_fields', 10, 1);
@cartimize
cartimize / custom_address_1_js_validation.js
Last active October 9, 2021 05:12
Custom JS validation for the following fields (billing_address_1, shipping_address_1)
jQuery( document.body ).on( 'cartimize_shipping_address_1_validation', function(event, defaultResult, fieldValue){
//Your custom code. Return true or false else it will use default validation
//Example: Validation for specific countries.
var selectedCountry = jQuery("#shipping_country").val();
if(selectedCountry == 'NL' || selectedCountry == 'BEL' || selectedCountry == 'CZE'){
return /\d/.test(fieldValue);
}
});
@cartimize
cartimize / custom_parsley_errors.php
Created October 8, 2021 10:31
Add custom error for front end validation
<?php
add_filter('cartimize_front_end_parsley_errors', 'cartimize_custom_cartimize_front_end_parsley_errors', 10, 1);
function cartimize_custom_cartimize_front_end_parsley_errors( $value ){
$value['parsley_errors']['shipping_address_1']= "Please enter your street address along with your house number";
$value['parsley_errors']['billing_address_1']= "Please enter your street address along with your house number";
return $value;
}
@cartimize
cartimize / address_1_field_always_show.php
Last active November 18, 2021 17:46
Address 2 field always show
<?php
add_filter( 'cartimize_get_billing_checkout_fields', 'cartimize_address_1_billing_fields_always_show' , 10, 1 );
function cartimize_address_1_billing_fields_always_show( $fields ){
if ( !isset( $fields['billing_address_2'] ) ) {
return $fields;
}
unset( $fields['billing_address_2']['is_hidden'] );
@cartimize
cartimize / shipping_fullname_virtual_product.php
Last active April 7, 2022 11:05
Shipping full name for virtual product
<?php
add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true', 50 );
add_filter( 'woocommerce_checkout_fields', 'custom_child_theme_override_checkout_fields', 100);
function custom_child_theme_override_checkout_fields($fields) {
if (! WC()->cart->needs_shipping()) {
foreach ( $fields['shipping'] as $key => $value ) {
if ( !in_array( $key, array('shipping_full_name', 'shipping_first_name', 'shipping_last_name') ) && stripos( $key, 'shipping_') !== false ) {
unset($fields['shipping'][$key]);
}