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-unset-int-orders-rule-af.php
Last active February 3, 2017 08:11
[WooCommerce] Remove the "international_order" rules in anti-fraud plugin
add_filter( 'wc_anti_fraud_rules', 'wc_remove_antifraud_rules');
function wc_remove_antifraud_rules( $rules ) {
foreach ( $rules as $key => $rule ) {
if ( 'international_order' === $rule->get_id() ) {
unset( $rules[$key] );
}
}
return $rules;
@rynaldos-zz
rynaldos-zz / wc-unset-bms-af-rule.php
Last active February 3, 2017 08:10
[WooCommerce] Remove the "WC_AF_Rule_Billing_Matches_Shipping" rule in anti-fraud Plugin
add_filter( 'wc_anti_fraud_rules', 'wc_remove_antifraud_rules');
function wc_remove_antifraud_rules( $rules ) {
foreach ( $rules as $key => $rule ) {
if ( 'billing_matches_shipping' === $rule->get_id() ) {
unset( $rules[$key] );
}
}
@rynaldos-zz
rynaldos-zz / wc-req-notes.php
Last active February 3, 2017 08:09
[WooCommerce] Make the Order_Comments Required
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['order']['order_comments']['required'] = true;
return $fields;
}
@rynaldos-zz
rynaldos-zz / wc-unset-myacc-tabs.php
Last active February 3, 2017 08:06
[WooCommerce] Unset tabs in my-account page
function unset_my_account_navigation_tabs( $items ) {
unset( $items['downloads'] );
// unset more items here
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'unset_my_account_navigation_tabs' );
@rynaldos-zz
rynaldos-zz / wc_instaup_img_cols.php
Last active February 3, 2017 08:05
[WooCommerce] Increase the image columns for Instagram
add_filter( 'woocommerce_instagram_columns', 'woocommerce_instagram_img_columns' );
function woocommerce_instagram_img_columns(){
return 6;
}
@rynaldos-zz
rynaldos-zz / wc-trs-free_label-app.php
Last active February 3, 2017 08:03
[WooCommerce] Table rates zero fees (append label)
function free_label_trs ( $label, $method ) {
if ( 0 == $method->cost && 'table_rate' == $method->method_id ) {
$label .= ' (' . __( 'Free', 'woocommerce-table-rate-shipping' ) . ')';
}
return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'free_label_trs', 10, 2 );
@rynaldos-zz
rynaldos-zz / wc-redirect-atc-checkout.php
Last active March 23, 2021 17:47
[WooCommerce] Redirecting from add-to-cart to checkout page
function my_custom_add_to_cart_redirect( $url ) {
$url = WC()->cart->get_checkout_url();
// $url = wc_get_checkout_url(); // since WC 2.5.0
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
@rynaldos-zz
rynaldos-zz / wc-vsl.php
Created September 21, 2016 09:40
Filter to add variable stock level totals back to admin
add_filter( 'woocommerce_admin_stock_html', 'tmt_show_variation_stock_level', 10, 2 );
function tmt_show_variation_stock_level( $stock_html, $the_product ) {
if( sizeof( $the_product->get_children() ) ) {
$stock_html .= ' (' . $the_product->get_total_stock() . ')';
}
@rynaldos-zz
rynaldos-zz / wc-add-vat-column-csv.php
Last active August 24, 2020 03:11
[WooCommerce] Add order export column for WooCommerce EU VAT number to Order / Customer CSV Exporter
// add custom column headers
function wc_csv_export_modify_column_headers( $column_headers ) {
$new_headers = array(
'column_1' => 'VAT Number',
// add other column headers here in the format column_key => Column Name
);
return array_merge( $column_headers, $new_headers );
}
@rynaldos-zz
rynaldos-zz / wc-sort-price-cost.php
Last active March 23, 2021 17:45
[WooCommerce] Sort the shipping prices by cost
add_filter( 'woocommerce_package_rates' , 'sort_woocommerce_available_shipping_methods_by_cost', 10, 2 );
function sort_woocommerce_available_shipping_methods_by_cost( $rates, $package ) {
if ( ! $rates ) {
return;
}
$tmp = array();
foreach( $rates as $rate ) {
$tmp[] = $rate->cost;
}