Displaying a WooCommerce product via PHP

Use do_shortcode(). For example, in a template, if you were wanting to display products specifically by ID: <?php echo do_shortcode(‘[products ids=”1, 2, 3, 4, 5″]’); ?> WooCommerce comes with several shortcodes which can be used to insert content inside posts and pages: http://docs.woothemes.com/document/woocommerce-shortcodes/ You can add shortcodes to a post or page easily via the … Read more

wpdb::prepare was called incorrectly

It’s always advised to use $wpdb->prepare when you are taking input from user. This will help in protecting queries against SQL Injection. For more details, check the Codex When you use $wpdb->prepare, you must pass the variables to the query. In your case, you can skip using $wpdb->prepare as you are using a hard coded … Read more

the_author_meta() vs get_the_author_meta()

If you look at the source code for the_author_meta(), it simply, in essence, just echo’s the result from get_the_author_meta(). WordPress has quite a lot of functions where functions with a the_* prefix simply echos the results from its get_* counter parts. The get_* prefix is almost always used for functions which return its results. There … Read more

Get php var inside javascript file (making plugin)

You can use wp_localize_script() to pass php variables to javascript. You create an array in php and then pass it to the function as the third parameter. It will come through as an object you name with the second parameter. First, register the script. wp_register_script( ‘custom-name-js’, plugins_url( ‘assets/custom-js.php’, __FILE__ ) ); Second, build your array … Read more

exclude multiple terms using get_terms() function

With get_terms(), the exclude parameter takes an array of term IDs, so just add the second term to the array: $terms = get_terms( TribeEvents::TAXONOMY, array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘exclude’ => array( 77, 71 ), ) ); echo ‘<li>Category:</li>’; foreach ( $terms as $term ) { echo ‘<li><a href=”‘.$url.’?tribe_eventcategory=’.$term->term_taxonomy_id.'”>’.$term->name.'</a></li>’; }

Query WooCommerce orders grouped by several order statuses

The documentation on wc_get_orders and WC_Order_Query is poor… Now regarding the order status in a WC_Order_Query, you can pass an array of order statuses: // Display “completed” orders count $statuses = [‘completed’]; $orders = wc_get_orders( [‘limit’ => -1, ‘status’ => $statuses] ); echo ‘<p>’ . sprintf( __(‘Count of “%s” orders: %s’), implode(‘”, “‘, $statuses), count($orders) … Read more

Using require_once in a Plugin?

The first one is like saying… Include the file found in the inc directory, above the directory where this file is located. The second statement is saying… in the server root (/) look in the inc folder for canagan_admin_functions.php and include it. The first one will work, the second won’t. In the second you’re looking … Read more

Place page title in header?

If you only need the title you can request it outside the loop easily. Try and call the_title() in your header. It should work But you have to be aware that if you don’t put a condition, each page of your website will display its title in the header section. EDIT: the function to call … Read more

Remove Woocommerce product link

The way I’ve done this was to take a copy of content-product.php and paste it into the root of your theme folder. Comment out do_action( ‘woocommerce_before_shop_loop_item_title’ ); and do_action( ‘woocommerce_after_shop_loop_item’ ); Quick and dirty, but it worked for me.