Hot answers tagged

7

An attachment is a Post The posts table contains information on the attachment post. In WordPress every uploaded media has it's own post entry, where post_type is 'attachment' and post_status is 'inherit'. In fact, you can get attachment post types using functions used to get other post types, like post, page or any CPT. That includes WP_Query, get_posts(...


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

Your edit got me to this idea, there indeed is no function called »woocommerce«, there is a class »WooCommerce« though. One thing to be aware of is, that the check has to late enough, so that plug-ins are actually initialized, otherwise - obviously - the class won't exists and the check returns false. So your check should look like this: if ( class_exists( '...


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

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

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

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' =...


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

This will definitly remove word category . Add this code in functions.php.As you already know woocommerce_template_single_meta is the hook responsible for meta information of the single-product. File is present in /woocommerce/templates/single-product/meta.php. Either you can use the following code to edit the html of meta.php or you can copy the file meta....


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

Do you really need to know the ID, for that see @PieterGoosens's answer, or do you just need to know if you are at the post type product archive? The latter can easily be achieved by using is_post_type_archive(): if ( is_post_type_archive( 'product' ) ) { // code }


2

If this is a true page, then you can get the ID of that specific page with get_queried_object_id(). This works and will return the ID on the specific pages, single, category, taxonomy, tag and author pages where it is used. True date and time archives and the homepage will not have ID's You can do the following $page_id = get_queried_object_id(); echo $...


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

Technically speaking, Woocommerce products are just another WordPress post object with a customized post type (which is product in this case). If you take a look at the create_product function inside class-wc-api-products.php, you'll see this line: // Attempts to create the new product $id = wp_insert_post( $new_product, true ); So the API ends up using ...


2

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


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 =)



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