lipisis
Forum Replies Created
-
Forum: Plugins
In reply to: [WooCommerce] Woocommerce hook to append shipping method formSee my previous answer if you want to add custom fields to the end of the form. If you want to add them for each shipping class, I used the following:
function shipping_instance_form_add_extra_fields($settings) { $new_settings = []; foreach($settings as $key => $setting){ $new_settings[$key] = $setting; if(str_starts_with($key, 'class_cost_')){ $new_settings[str_replace('class_cost_', 'class_pack_', $key)] = [ 'title' => str_replace('shipping class cost', 'units per package', $setting['title']), 'type' => 'number', 'description' => '', ]; } } return $new_settings; } function shipping_instance_form_fields_filters() { $shipping_methods = WC()->shipping->get_shipping_methods(); foreach ($shipping_methods as $shipping_method) { add_filter('woocommerce_shipping_instance_form_fields_' . $shipping_method->id, 'shipping_instance_form_add_extra_fields'); } } add_action('woocommerce_init', 'shipping_instance_form_fields_filters');
You don’t need to do any saving. It will be automatically saved.
Later, if you have WC_Shipping_Method instance, you can retrieve your custom fields with the following:
$method->get_instance_option('class_pack_'.$class_id);
Forum: Plugins
In reply to: [WooCommerce] Woocommerce hook to append shipping method formEssentially I want to amend prices for shipping classes in a same way this answer does but on that answer you can see it’s hardcoded to only apply to one specific shipping class (TShirt) and threshold of “5”. So I want to have individual thresholds for every shipping class (that’s why I need those extra inputs).
With that I would eventually be able to say “Charge £5 for every 3 TShirts + charge £2 for every 5 Jeans” and so on.
I didn’t quite try it yet, but I think the following code is pretty close to what I need (source)
function shipping_instance_form_add_extra_fields($settings) { $settings['custom_shipping_id'] = [ 'title' => 'Custom Shipping ID', 'type' => 'number', 'description' => '', ]; return $settings; } function shipping_instance_form_fields_filters() { $shipping_methods = WC()->shipping->get_shipping_methods(); foreach ($shipping_methods as $shipping_method) { add_filter('woocommerce_shipping_instance_form_fields_' . $shipping_method->id, 'shipping_instance_form_add_extra_fields'); } } add_action('woocommerce_init', 'shipping_instance_form_fields_filters');
- This reply was modified 2 years, 9 months ago by lipisis.
Hi @webtoffee ,
That sorted the issue, thank you. Is it worth adding some sort of message about this on your plugin for any other people coming across this in a future ? ??
P.S. Regarding sandbox site access, I don’t mind anyone accessing that site as it was available only for 7 hours and it doesn’t contain any sensitive information, all accounts used were created specifically for this thread. Thanks for a notice anyways
Hi @webtoffee ,
That was a great suggestion. I’ve disabled Smashballoon instagram feed plugin (only Smashballoon plugin we have) and now Google Analytics cookies are only added after giving a consent.
I looked into this more on a sandbox wordpress site more and I can tell that this whole issue occurs if you have instragram feed shortcode present on the page only. Having Smashballoon plugin enabled in itself does not break it.
Here is how I was able to re-create the issue on the sandbox site (see sandbox site details at the end of this post):
1. Install and configure both, Monsterinsight’s and Smashballoon’s plugins
2. Go to front end and see that GA cookies are not added to your browser (correct behaviour)
3. Edit homepage and add[instagram-feed]
shortcode.
4. Go to front end again and see that GA cookies were added straight away before giving a consent (incorrect behaviour)The moment you remove instagram feed shortcode, everything works again. Hope that helps to solve this bug .
WordPress site: https://s-qzrvbylrdmngl.eu1.wpsandbox.org WordPress admin area: https://s-qzrvbylrdmngl.eu1.wpsandbox.org/wp-admin/ Username: demo Password: demo Access Code: 475 !!! Only accessible for 7 hours !!!
Here is the versions of the plugins:
Google Analytics for WordPress by MonsterInsights – 7.17.0
GDPR Cookie Consent – 2.0.4Hi @webtoffee
I’ve tried clearing Autoptimize cache but that didn’t help. I even disabled Autoptimize plugin itself and that didn’t solve the issue neither.
For the sake of testing, I’ve disabled all plugins except your plugin and MonsterInsight one. Still, it was the same issue, opening new incognito window still added GA cookies without giving any consent (see screenshot url below)
Is there anything else you could suggest please?