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

How to extend a plugin like we do a theme?

There’s no standard method apart from hooks, and it’s up to the developer of the original plugin to add and support these. If the plugin is extendable they will have developer documentation (LearnDash’s is available here). The specifics will depend entirely on the plugin and how they’ve chosen to allow it.

How to get an image transferred via FTP or script to appear in Media Manager?

add this to your for each and $filename to each file, $wp_filetype = wp_check_filetype(basename($filename), null ); $attachment = array( ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($filename)), ‘post_content’ => ”, ‘post_status’ => ‘inherit’ ); $attach_id = wp_insert_attachment( $attachment, $filename, 0 ); // you must first include the image.php file // for the function wp_generate_attachment_metadata() to … Read more

WordPress select dropdown list in widget

See my comment above…you’re using get_field_id() on the name-attribute, where it should be get_field_name(). get_field_id() returns ‘widget-‘.$this->id_base.’-‘.$this->number.’-‘.$field_name, whereas get_field_name() returns ‘widget-‘.$this->id_base.'[‘ . $this->number . ‘][‘ . $field_name.’]’