Skip to content

Instantly share code, notes, and snippets.

@xadapter
xadapter / functions.php
Created Jun 16, 2016
WooCommerce - Unset the required property of fields on checkout page.
View functions.php
add_filter( 'woocommerce_checkout_fields' , 'xa_checkout_change_required_fields_to_optional' );
function xa_checkout_change_required_fields_to_optional( $fields ) {
$fields['billing']['billing_address_1']['required'] = false;
$fields['billing']['billing_address_2']['required'] = false;
$fields['billing']['billing_postcode']['required'] = false;
$fields['billing']['billing_city']['required'] = false;
$fields['billing']['billing_phone']['required'] = false;
return $fields;
}
@xadapter
xadapter / functions.php
Last active Aug 9, 2016
Change WooCommerce Cart / Checkout Options based on User Role and Country
View functions.php
add_action('woocommerce_available_payment_gateways', 'xa_change_optins_based_on_user_role');
function xa_change_optins_based_on_user_role(){
global $woocommerce;
// Check with the capability which is unique to the particular user role.
if( current_user_can( 'edit_posts' ) {
//
if ( isset( $available_gateways['ccavenue'] ) && $woocommerce->customer->get_country() <> 'IN' ) {
unset( $available_gateways['ccavenue'] );
} else if ( isset( $available_gateways['paypal'] ) && $woocommerce->customer->get_country() == 'IN' ) {
unset( $available_gateways['paypal'] );
@xadapter
xadapter / functions.php
Created Aug 11, 2016
WooCommerce - Change a Required Checkout Field to Optional
View functions.php
add_filter( 'woocommerce_billing_fields', 'xa_filter_billing_phone', 10, 1 );
function xa_filter_billing_phone( $address_fields ) {
$address_fields['billing_phone']['required'] = false;
return $address_fields;
}
@xadapter
xadapter / functions.php
Created Aug 11, 2016
WooCommece - Override Existing Checkout Fields
View functions.php
add_filter( 'woocommerce_checkout_fields' , 'xa_override_existing_checkout_fields' );
function xa_override_existing_checkout_fields( $fields ) {
$fields['order']['order_comments']['placeholder'] = 'Let us know your color preference.';
$fields['order']['order_comments']['label'] = 'Gift Wrap Preference';
return $fields;
}
@xadapter
xadapter / functions.php
Last active Mar 13, 2017
Alter UPS Order XML Export Data with Order/Coupon/Subscription import export plugin
View functions.php
function alter_ups_order_xml_export_data( $order_details ) {
foreach ($order_details as $key => $value) {
$order_details[$key]['Shipment']['ShipFrom']['UPSAccountNumber'] = 'xxxxxx'; // UPS Account Number
$order_details[$key]['Shipment']['ShipmentInformation']['ServiceType'] = 'GND'; // UPS ServiceType
$orderID = $order_details[$key]['Shipment']['ShipmentKey'];
$order = new WC_Order($orderID);
$coupons_list = ' CouponCode:';
foreach( $order->get_used_coupons() as $coupon) {
@xadapter
xadapter / functions.php
Created Apr 18, 2017
Remove some shipping services based on country with DHL WooCommerce Shipping.
View functions.php
add_filter('woocommerce_package_rates', 'wf_remove_shipping_options_for_particular_country', 10, 2);
function wf_remove_shipping_options_for_particular_country($available_shipping_methods, $package){
global $woocommerce;
$country_list = array(
'CA' => 'wf_dhl_shipping',
'US' => 'wf_dhl_shipping',
);
$customer_country = $woocommerce->customer->get_shipping_country();
@xadapter
xadapter / functions.php
Last active Jul 4, 2017
WooCommerce - Add new Custom Fields to Emails
View functions.php
add_filter('woocommerce_email_order_meta_keys', 'xa_email_custom_order_meta_keys');
function xa_email_custom_order_meta_keys( $field_keys ) {
// Please make sure the Custom Field 'tracking_code' is added to the Checkout Field.
$field_keys[] = 'tracking_code';
return $field_keys;
}
@xadapter
xadapter / functions.php
Created Oct 4, 2017
Alter or hide order meta details in Invoice, Packing Slip & Delivery notes with Print Invoice, Packing Slip, Delivery Note & Label for WooCommerce
View functions.php
//code snippet to replace meta key with value
add_filter('wf_pklist_modify_meta_data', 'wf_pklist_change_meta_data_label', 1);
function wf_pklist_change_meta_data_label($meta_data)
{
//replace the array key value with your custom key value.
$label_array = array(
'_wcj_product_input_fields_local_1' => 'Global Desc',
'_wcj_product_input_fields_global_1' => 'Local Desc'
);
@xadapter
xadapter / functions.php
Created Oct 12, 2017
Add product dimensions in Invoice with Xadapter Print Invoice, Packing Slip, Delivery Note & Label for WooCommerce
View functions.php
add_filter('woocommerce_order_product_title', 'xa_product_dimension_add_func',99,2);
function xa_product_dimension_add_func($item_name ='', $product ='')
{
if(!empty($product))
{
return $item_name . ' <small>( '.wc_format_dimensions($product->get_dimensions(false)).' )</small>';
}else
{
return $item_name;
@xadapter
xadapter / functions.php
Created Oct 12, 2017
Add product dimensions in Packing Slip and Delivery Note with Xadapter Print Invoice, Packing Slip, Delivery Note & Label for WooCommerce
View functions.php
add_filter('woocommerce_order_product_title_for_pk_list', 'xa_product_dimension_add_func',99,2);
function xa_product_dimension_add_func($item_name ='', $product ='')
{
if(!empty($product))
{
return $item_name . ' <small>( '.wc_format_dimensions($product->get_dimensions(false)).' )</small>';
}else
{
return $item_name;
You can’t perform that action at this time.