Skip to content

Instantly share code, notes, and snippets.

View aliciaiceland's full-sized avatar

aliciaiceland

View GitHub Profile
@aliciaiceland
aliciaiceland / functions.php
Created June 6, 2019 06:53
Add field to product enquiry form
/*
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,
@aliciaiceland
aliciaiceland / functions.php
Created December 28, 2017 09:47
Add to product details page
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;
}
@aliciaiceland
aliciaiceland / functiuons.php
Created July 11, 2017 06:09
Split cart by shipping classes
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(
@aliciaiceland
aliciaiceland / plugin_page.php
Created June 4, 2017 19:55
Add Settings Link To Plugin Listing Page
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 );
}
@aliciaiceland
aliciaiceland / plugin_page.php
Created June 4, 2017 19:55
Add Settings Link To Plugin Listing Page
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 );
}
@aliciaiceland
aliciaiceland / functions.php
Created May 29, 2017 11:33
Pre-populate Woocommerce checkout fields
<?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;
@aliciaiceland
aliciaiceland / functions.php
Created May 24, 2017 06:20
Modify flat rate shipping cost
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 );
@aliciaiceland
aliciaiceland / functions.php
Last active April 11, 2017 06:25
Disable payment gateway for shipping method
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' );