UWooCommerce – add cart discount programmatically?

I haven’t applied any discounts like that before, but have done it with ‘fees’ a lot. Adding a fee is quite easy: function custom_wc_add_fee() { WC()->cart->add_fee( ‘Fee’, -10 ); } add_action( ‘woocommerce_cart_calculate_fees’,’custom_wc_add_fee’ ); (or if you want a plugin solution, I created this plugin: https://aceplugins.com/plugin/woocommerce-advanced-fees/)

Delay JavaScript files from loading

I think you should use setTimeout to pause the execution of the script without blocking the UI. setTimeout(function(){ //your code to be executed after 2 seconds }, 2000); So your code will become. setTimeout(function(){ document.addEventListener(“DOMContentLoaded”, function(event) { document.getElementsByTagName(“body”)[0].setAttribute(“ng-app”, “app”); }); }, 2000); This will delay script execution for 2 seconds. You can change this value … Read more

is pre_get_comments not working?

I don’t see any reason why pre_get_comments would not be working, it’s still in core, however… you’ve got a few problems in your code – do_action_ref_array is what core calls to trigger the action, you add your own functions to the action queue via add_action. orderby is the field name you want to order by, … Read more

Update Data parameter of a wp_localize_script() call

wp_localize_script results in your data being printed to the page before your script tag via PHP, whether it be in wp_head or wp_footer, depending on where you’ve set your script to be output. Calling wp_localize_script from an AJAX handler won’t do anything, you’re returning data via JavaScript. What you can do is put any data … Read more

How do I link to a php file in my plugin directory?

You can use admin.php?action=my_action and WordPress will fire the equivalent action hook: // How to get the URL $url = admin_url( “admin.php?action=wpse_21460_export&any_other_arguments” ); // How to handle the URL function wpse_21460_export() { // Do your export and exit } add_action( ‘admin_action_wpse_21460_export’, ‘wpse_21460_export’ ); See how WordPress formats the hook name to admin_action_{value_of_action_param}

Does a blank plugin come with any overhead?

No, outside of purely technical aspects of PHP includes (as you correctly pointed out), there is no additional overhead to plugin quantity on general WordPress core load.. The list of active plugins is calculated in advance and stored persistently. The load process just runs over it and performs PHP includes on each. The edge cases … Read more