Hot answers tagged

6

I solve This To get the current category ID. $cate = get_queried_object(); $cateID = $cate->term_id; echo $cateID; and it works like a charm.


5

You should use 'orderby' => 'meta_value_num' and 'meta_key' => 'rating' as specified by the WordPress Codec. Using meta_value_num with the assumption your ratings are numeric values Reference: Orderby Parameters


4

seems woocommerce doesn't have any filters when registering their endpoints, https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-query.php#L84 so you need to add your new endpoint on init hooks, just like this add_action( 'init', 'add_endpoint' ); function add_endpoint(){ add_rewrite_endpoint( 'license', EP_ROOT | EP_PAGES ); } ...


4

Change your args to be like this: $meta_query = WC()->query->get_meta_query(); $meta_query[] = array( 'key' => '_featured', 'value' => 'yes' ); $args = array( 'post_type' => 'product', 'stock' => 1, 'showposts' => 6, 'orderby' => 'date', 'order' => 'DESC', 'meta_query' =...


4

I know this post is old, but to keep this question updated: As of WooCommerce 2.4.4 woocommerce_process_product_meta_variable no longer works, and it must be changed to woocommerce_save_product_variation So, Change: add_action( 'woocommerce_process_product_meta_variable', 'save_variable_fields', 10, 1 ); Into: add_action( '...


4

Here's my code for creating a subscription -- it took a lot of trial and error to figure it all out. Best of luck! function create_test_sub() { $email = 'test@test.com'; $start_date = '2015-01-01 00:00:00'; $address = array( 'first_name' => 'Jeremy', 'last_name' => 'Test', 'company' => '', 'email' ...


4

Seems like there are a lot of meta keys you can order by (here is a list I’ve found). However I couldn’t find anything rating related. I searched for rating in the WooCommerce source code and found this line: includes/abstracts/abstract-wc-product.php#L1087 So here is what finally worked for me in the context of using the WooCommerce PHP REST API client: ...


4

WooCommerce allows you to override its default templates. All templates are located in a woocommerce/templates folder. All you have to do is to create a woocommerce folder within your theme’s directory, and in this folder duplicate the files you’d like to override. If you want to update the markup then you will need to copy archive-product.php and content-...


4

You're damned if you do, and you're damned if you don't. But it's typically better to "do". I have been working in WordPress support and development for a number of years now - and I can certainly say it's much better to keep everything up to date. Wait a little bit (2 weeks or so) after major updates before making the change to allow time for maintenance ...


3

Orders are just regular posts: wp_delete_post($order_id,true);


3

There is almost never a scenario where executing PHP code entered from the wysiwyg editor is a good idea. It opens up a whole bunch of security issues. The best way to achieve what you are looking for is to setup a custom short code that will return the link you are interested in. Add something like this to your functions.php file in your theme. ...


3

To check if woocommerce or anyother plguin is active, paste the following code on the template where you want to display the message. if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { echo 'WooCommerce is active.'; } else { echo 'WooCommerce is not Active.'; }


3

I would add it from the start so you don't have to go back to it, and it's a really simple process of creating a woocommerce.php file in your theme and then add the following to your functions.php add_action( 'after_setup_theme', 'woocommerce_support' ); function woocommerce_support() { add_theme_support( 'woocommerce' ); } To create the woocommerce....


3

OK so I had a variation of this same problem myself and I'll walk you through it. All works fine, except for one thing: WooCommerce custom product attributes are not displayed instantly in dropdown/select filters on the website. However, 'manually' pressing Update on the Wordpress-page does the job. When displaying attributes woocommerce does this ...


3

The code you have provided is incomplete. Not sure if that is the only code you are using to achieve what you want. So, besides first code block which you have provided, bellow I am adding all rest of the code which is required to show the new field on backend in 'Order Details' box and make it editable through custom fields. Please note, in your second code ...


3

You may need to include a tax_query for the Woocommerce taxonomy (called 'product_cat'): $tax_query = array( array( 'taxonomy' => 'product_cat' ), ); $query->set( 'tax_query', $tax_query ); } return $query; } However, you'll have to ensure that you can return posts AND pages AND product categories and also ...


3

I think you are on the right track, wp_cache_delete was what finally helped me get an auto-signup with auto-login plugin working... I have this from there: wp_cache_delete($current_user->ID, 'users'); wp_cache_delete($current_user->user_login, 'userlogins'); Then see what roles you get after that with: $current_user = wp_get_current_user();


2

It seems that the OP have managed to solve his/her problem by doing this, which can be found at Different menus for logged-in users. if ( is_user_logged_in() ) { wp_nav_menu( array( 'theme_location' => 'logged-in-menu' ) ); } else { wp_nav_menu( array( 'theme_location' => 'logged-out-menu' ) ); } The more shorter way to achieve that is by ...


2

Cron/Scheduled tasks and a DB crawl is your friend It would need to be a plugin, you could assign it a wp_cron interval even, not much unlike the one suggested above but with the addition of checking any 'post_content' like field (you will need to identify these, dependent upon your WP environment) for the image's URI/URL. This has the potential to be ...


2

Product category is just a regular wordpress taxonomy. You can get the link like this: echo esc_url( get_term_link( 6, 'product_cat' ) ); You can use slugs too: echo esc_url( get_term_link( 'category-slug', 'product_cat' ) );


2

As explained in their documentation WooCommerce provides a templating structure. Copying WC in your theme won't get you anywhere. Create a woocommerce folder in your theme. Copy any template inside the templates folder of WC inside your woocommerce theme folder. Beware you need to keep the structure from templates folder intact in your woocommerce theme ...


2

Unfortunately, it's not possible with all plugins. This is a feature the developer has to provide on their own. Usually how it works is the plugin will look for the template file in the child theme first. If it's not found there, it looks for the template in the parent theme. Finally, if it's not found in either of those places, it uses the template ...


2

You can hook into woocommerce_variable_price_html and reformat the price to include or. This will replace the – with or on all products with multiple differing prices. add_filter('woocommerce_variable_price_html', 'custom_variation_price_seperator', 10, 2); function custom_variation_price_seperator( $price, $product ) { $price = ''; $...


2

remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10,0); remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20,0); remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10,0); I hope it works for you =)


2

This is because you're doing it too early. You need to wrap your code in the necessary hook so that it occurs at the correct time. Because you don't tell get_field the ID of the current post, it needs to know which post to get the field from, and it does this by referencing the global variable $post, which gets set when you call the_post, or by WP Core ...


2

If you look at woocommerce/templates/content-single-product.php you'll see that the product summary is constructed using hooks with different priorities. Here's the relevant section: <?php /** * woocommerce_single_product_summary hook * * @hooked woocommerce_template_single_title - 5 * @hooked ...


2

You have a typo in $_SESSION['odertype'], should be $_SESSION['ordertype']. You are also ASSIGNING a value instead of testing it for equivalency, try ==. If in doubt you can always use var_dump($_SESSION) to get all the values stored there.


2

Following @Burgi's answer, the correct snippet should be: function jk_woocommerce_quantity_input_args( $args, $product ) { if ( isset( $_SESSION['ordertype'] ) && // Never assume an array index exists $_SESSION['ordertype'] == 'local_delivery' && // Note == "same as" operator, not = "assign" $product->...


2

You're close - just need to tweak your arguments: <?php echo get_user_meta( $customer_id, 'billing_phone', true ) ?> Just make sure $customer_id is the ID of the user - you probably want get_current_user_id() instead.


2

Just round the decimal to two digit as per your requirement. $myID = 2859; $myorder = new WC_Order($myID); foreach ($myorder->get_items('line_item') as $item) { $rounded_total = round($item["line_total"],2);// allow 2 decimal and avoid further $Data = $Data.OrderLine($item["name"], $rounded_total, $item["line_tax"], $item["qty"], "...



Only top voted, non community-wiki answers of a minimum length are eligible