Add multiple shipping rates from add_rate function with custom ID

to understand how to store choosen method id or else try using: // Make a shipping rate for each result foreach ($quote->shipping_options as $option) { $rate = array( ‘id’ => ‘my_method_’.$option->id, ‘label’ => $methodNames[$option->name], ‘cost’ => $option->price, ‘meta_data’ => array(), ); // Register the rate $this->add_rate($rate); } in ‘meta_data’ you can store whatever you wantin … Read more

Performance of several get_option() calls

If you check the implementation of get_option() you’ll see that in line 168 it calls wp_cache_get() like so: $value = wp_cache_get( $option, ‘options’ ); This means multiple calls to get_option(“style_settings”) within the same PHP execution will be served from cache. There is no need to re-invent this, as you might break other functionality with it. … Read more

Passing array of strings to a SQL statement in a WordPress plugin

$wpdb->prepare() accepts a single array of arguments as the second parameter, e.g. $wpdb->prepare( “SELECT * FROM table WHERE field1 = %s AND field2 = %d AND field3 = %s”, array( ‘foo-bar’, 123, ‘[email protected]’ ) ) Therefore you can use an array of placeholders with the SQL command (the 1st parameter), like so: // Create an … Read more

Creating a modal dialog without jQuery

The WordPress admin area uses Thickbox, which is still a jQuery plugin (jQuery is used all over the admin area). You need to enqueue the script and style (add_thickbox() does this for you), and then all links that have class thickbox will be converted. You need to add some URL parameters too, for example the … Read more