How does wordpress distinguish a plugin’s main php file from other php files? [duplicate]

WordPress has no convention for naming of main file. It scans whole plugins directory (see get_plugins() ) and looks for plugin header (with get_plugin_data())in every PHP file on appropriate directory levels. This is only performed when you actually need full list of plugins. Thing like active plugins are calculated and stored separately so that for … Read more

Why is my ajax call refreshing the page?

Try using preventDefault(), it’s a jQuery function for preventing default actions called by the browser. First you should call an event handler by firing up your submitter. You can do this as follow: $(‘#my_upload_form’).submit(function (event) { After catching a submit and giving an event with it, you should prevent the default refresh of a browser: … Read more

Rewrite url for existing page without flush_rewrite_rules

If you want to rewrite example.com/test123 (a standard WordPress Page) to example.com/test234 (another standard WordPress Page) without having to save the rewrite rules in the database, then one option is using the request filter hook: add_filter( ‘request’, function ( $query_vars ) { if ( isset( $query_vars[‘pagename’] ) ) { $slug = $query_vars[‘pagename’]; // Define a … Read more

How do I hook a custom discount to change a WC_Order price total on WooCommerce?

I would suggest adding a “virtual” coupon to the order which would represent the store credit. Coupons are applied on the cart page before checkout, this is where I would hook in. You can use something like the woocommerce_cart_subtotal filter as per my example below: function royal_woocommerce_filter_checkout_for_coupons( $subtotal, $compound, $cart ) { // Your logic … Read more

Plugin vs Settings load order (woocommerce dependency)

The problem is, by the time your WooCommerce_Chilexpress_Tags_Settings is defined, WC_Settings_Page has indeed not yet loaded; hence you got the fatal error. And if you want to do it the same way that WooCommerce does it, place the WooCommerce_Chilexpress_Tags_Settings in a separate PHP file, e.g. includes/class-woocommerce-chilexpress-tags-tettings.php, and initialize the class from that file — i.e. … Read more