This file contains hidden or 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 field to your product enquiry form | |
*/ | |
add_filter('product_enquery_fields',function($fields){ | |
$new_fields = $fields; | |
$new_fields['company'] = array( | |
'label' => __('Company', 'woocommerce'), | |
'type' => 'text', | |
'weight'=>9, |
This file contains hidden or 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_product_tabs', 'add_my_tab'); | |
function add_my_tab($tabs){ | |
$tabs['details_tab'] = array( | |
'title' => 'New Tab', | |
'priority' => 1, | |
'callback' => 'tab_content', | |
); | |
return $tabs; | |
} |
This file contains hidden or 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_cart_shipping_packages', 'split_cart_by_shipping_class' ); | |
function split_cart_by_shipping_class($packages){ | |
$packages = array(); | |
$new_packages = array(); | |
// Group of shipping class | |
$class_groups = array( |
This file contains hidden or 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( 'plugin_action_links_' . plugin_basename(__FILE__), 'myplugin_add_action_links' ); | |
function myplugin_add_action_links ( $links ) { | |
$mylinks = array( | |
'<a href="' . admin_url( 'options-general.php?page=myplugin_settings' ) . '">Settings</a>', | |
); | |
return array_merge( $links, $mylinks ); | |
} |
This file contains hidden or 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( 'plugin_action_links_' . plugin_basename(__FILE__), 'myplugin_add_action_links' ); | |
function myplugin_add_action_links ( $links ) { | |
$mylinks = array( | |
'<a href="' . admin_url( 'options-general.php?page=myplugin_settings' ) . '">Settings</a>', | |
); | |
return array_merge( $links, $mylinks ); | |
} |
This file contains hidden or 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 | |
/** | |
* Pre-populate Woocommerce checkout fields | |
*/ | |
add_filter('woocommerce_checkout_get_value', function($input, $field ) { | |
global $current_user; | |
switch ($field) : | |
case 'billing_first_name': | |
case 'shipping_first_name': | |
return $current_user->first_name; |
This file contains hidden or 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 flat_rates_cost( $rates, $package ) { | |
foreach($rates as $key => $rate){ | |
if($rate->method_id == 'flat_rate'){ | |
// Put your logic and modify | |
$rates[$key]->cost = 25; | |
} | |
} | |
return $rates; | |
} | |
add_filter( 'woocommerce_package_rates', 'flat_rates_cost', 10, 2 ); |
This file contains hidden or 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 disable_payment_gateways( $gateways ) { | |
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' ); | |
// if 'local delivery' is chosen as shipping rate | |
if ( in_array( 'local_delivery', $chosen_shipping_rates ) ) : | |
// Removing bank transfer payment gateway, you can unset other gateways too. | |
unset( $gateways['bacs'] ); | |
endif; | |
return $gateways; | |
} | |
add_filter( 'woocommerce_available_payment_gateways', 'disable_payment_gateways' ); |