Tips of the Plugin Woocommerce Shipping Price By Place
Hi!, due to the high traffic of this plugin, we will show how to take advantage of the functionalities through the filters that this plugin provides.
1. Change the settings values for default.
In the checkout page the plugin show the message “Choise zone1/zone2” and when there is not zones to show, the message is “There is not zone1/zone2”.
These are values for default, but you change them using the filter“woocommerce_shipping_gowoo_shiplace_{instance_id}_settings”, here a example:
<?php add_filter('woocommerce_shipping_gowoo_shiplace_29_settings','gowooship_customize_label',10,1); function gowooship_customize_label($array_settings) { $array_settings['places_info']['label_textdefault'] = 'There is not Townships'; $array_settings['places_info']['label_choise'] = 'Choise your Townships'; return $array_settings; } ?>
2. Add atributte to fields of plugins
If you wish change some atributtes of the fields of plugins you can use the hook “gowoo_checkout_fields”. For example, if we want to add a class called “entry-field”.
<?php add_filter('gowoo_checkout_fields','gowooship_add_class',10,1); function gowooship_add_class($array_fields) { $array_fields['billing']['billing_gowoo_place']['class'][] = 'custom-class'; return $array_fields; } ?>
3. Remove shipping method
If need remove this method because of some bussines rules, you need use the filter“woocommerce_shipping_gowoo_shiplace_{instance_id}_is_available”. For example, if the order total is great than 1000, then remove it.
<?php add_filter('woocommerce_shipping_gowoo_shiplace_29_is_available','gowooship_is_available',10,1); function gowooship_is_available($package) { if( $package['contents_cost'] > 1000 ) return false; return true; } ?>
4. Remove some payments methods when choose a place of this shipping method
Sometimes we need remove some payment method when do a action, in this case when we choose a place using this plugin. Woocommerce has a filter it can help us, it is called“woocommerce_available_payment_gateways”.
For example if want to remove “Cash on Delivery” when choose some place, then we must know the instance_id, the id of place and the code of payment method and this case the code is COD.
add_filter('woocommerce_available_payment_gateways','gowooship_addremove_payments',10,1); function gowooship_addremove_payments($array_payments) { //This is the current method shipping $current_payment = WC()->session->get('chosen_shipping_methods'); $data_payment = explode(':',$current_payment[0]); //This fields you can modfify. $level2_id = 2; $instance_id = 29; $payment_to_remove = 'cod'; /********************************************** STEP1 WE SEARCH THE ZONE2 CHOISE FOR THE USER ***********************************************/ //$_POST['post_data'] Contain all values of checkout form //field1=val1&field2=val2&field3&val3&field4=val4 if( isset($_POST['post_data']) && $data_payment[0] == 'gowoo_shiplace' && $data_payment[1] == $instance_id ) { //Split by & and save it in a array $array_form = explode('&',$_POST['post_data']); if(is_array($array_form)) { //Split by = and save it in other array foreach($array_form as $array_fields) { $array_values = explode('=',$array_fields); if( $array_values[0] == 'billing_gowoo_place' && !empty($array_values[1]) ) { $data_select = $array_values[1]; break; } } } /********************************************** STEP2: REMOVE THE PAYMENT ***********************************************/ //$data_select in the key of the level2_id if( isset($data_select) && $data_select == $level2_id ) { unset($array_payments[$payment_to_remove]); } } return $array_payments; }
If you want to purchase this plugin, you can follow this links: