Extra Fees Plugin Actions and Filters
Actions and Filters
1. Custom filter for optional fee section on the checkout page.
Code:
add_filter( 'wcpfc_optional_fee_text', 'custom_title_for_optional_fee', 10 ); function custom_title_for_optional_fee( ) { //Custom title for optional fee section on checkout return 'WILL THIS BE STUDENT PACK?'; }
Screenshot 1: (Checkout page default layout)
Screenshot 2: (Checkout page layout after the filter applies)
2. Change the default standard tax to your predefined tax on fees
Code:
add_filter( 'wcpfc_tax_class', 'dots_change_fee_tax_class_by_id', 10, 2 ); function dots_change_fee_tax_class_by_id( $tax_class, $fee_id ) { //default $tax_class = 'standard' eg. 7% //if fees id match then it will change the tax class to custom if( 21841 === $fee_id ){ $tax_class = 'standard-19'; //custom tax class eg. 19% } return $tax_class; }
Description: Add the above filter in the functions.php file and change $fee_id with your ID
3. Change the position of the optional fees section
Code:
add_filter( 'optional_fee_display_default_hook', 'optional_fee_display_default_hook_custom', 10,1 ); function optional_fee_display_default_hook_custom( $default_title ) { return 'woocommerce_review_order_before_payment'; //OR //return 'woocommerce_after_order_notes'; }
Description: Default it will display the fee before the payment options on the checkout page but you can change the hook based on the custom theme.
4. Change 'All fees' titles once the 'merge fees' option is selected
Code:
function wcpfc_all_fee_title_new( $fee_title ) { return "Your Fee Title"; } add_filter( 'wcpfc_all_fee_title', 'wcpfc_all_fee_title_new', 10, 1 );
5. Change 'All fees' titles once the 'merge fees' option is selected
Code:
/**** UPS plugin compatibility code end */ /** Filter to showcase all the fee based on allowed shipping IDs */ add_filter('ups_specific_fee_filter', 'ups_specific_fee_filter_callback',$args, 1); function ups_specific_fee_filter_callback($args){ $args['flag'] = 1; // default 0 to disable $args['fee_list'] = array(); //add list of fees Ids to check specific only $args['allowed_shipping_ids'] = array('03'); // add list of shipping method Ids to allowed fee return $args; } /**** UPS plugin compatibility code start */ $ups_specific_fee_filter = apply_filters('ups_specific_fee_filter', $args = array('flag'=> 0, 'fee_list' => array(), 'allowed_shipping_ids' => array())); /**Convert all the argument to variables */ $custom_condition_flag = $ups_specific_fee_filter['flag']; $allowed_fee_list = $ups_specific_fee_filter['fee_list']; $allowed_shipping_ids = $ups_specific_fee_filter['allowed_shipping_ids']; /** Check if filter code enable or not */ if( 1 === $custom_condition_flag ){ /** Check if there is selected fees want to chcek or not */ if(isset($allowed_fee_list) && !empty($allowed_fee_list)){ if( in_array($fees_id,$allowed_fee_list ) ){ if ( $wc_curr_version >= 3.0 ) { $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); } else { $chosen_shipping_methods = $woocommerce->session->chosen_shipping_methods; } if ( ! empty( $chosen_shipping_methods ) ) { $chosen_shipping_methods_explode = explode( ':', $chosen_shipping_methods[0] ); //$selected_shipping_name = $chosen_shipping_methods_explode[0]; $selected_shipping_id = $chosen_shipping_methods_explode[1]; /** Check if selected shipping match with allowed shipping Ids or not */ if( in_array( $selected_shipping_id, $allowed_shipping_ids ) ) { $is_passed['has_fee_based_on_shipping_method'] = 'yes'; } else { $is_passed['has_fee_based_on_shipping_method'] = 'no'; } } } } else { //** If there is no allowed fee added then apply on all the fees */ if ( $wc_curr_version >= 3.0 ) { $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); } else { $chosen_shipping_methods = $woocommerce->session->chosen_shipping_methods; } if ( ! empty( $chosen_shipping_methods ) ) { $chosen_shipping_methods_explode = explode( ':', $chosen_shipping_methods[0] ); //$selected_shipping_name = $chosen_shipping_methods_explode[0]; $selected_shipping_id = $chosen_shipping_methods_explode[1]; if( in_array( $selected_shipping_id, $allowed_shipping_ids ) ){ $is_passed['has_fee_based_on_shipping_method'] = 'yes'; } else { $is_passed['has_fee_based_on_shipping_method'] = 'no'; } } } }