Tag Info

Hot answers tagged

6

An attachment is a Post The posts table contains information on the attachemnt 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 include WP_Query, ...


5

Looks like I figured it out. I used get_term_link. And I was getting an error because I was using it this way: get_term_link( $woo_cat_id, 'product_cat' ); Which gave me this error: Object of class WP_Error could not be converted to string So I went this route instead with the slug and it worked: $prod_cat_args = array( 'taxonomy' => ...


4

You could check to see if the 'WooCommerce' class exists, then run the code that requires WooCommerce. <?php if ( class_exists( 'WooCommerce' ) ) { // code that requires WooCommerce } else { // you don't appear to have WooCommerce activated } ?>


4

There are approx. 10,000 items returned by the query. That's your problem right there. No matter what you do inside the loop, WordPress is still loading 10,000 post objects into memory. Batch it up and sprinkle a little magic in your query arguments: $args = array( 'fields' => 'ids', // MAGIC! Just get an array of id's, no objects ...


4

The problem with your approach is that woocommerces product category is a custom taxonomy called product_cat. But with cat you are addressing the built-in category. Taxonomies can be addressed with a tax query, simplified example below: function wpse188669_pre_get_posts( $query ) { if ( ! is_admin() && ...


3

Okay, based on answers on link above (where I got the old code and there are people that help to answered), I put the modification code for my website. I tried it and it's working like charm. Change: add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 2 ); Into : add_action( 'woocommerce_variation_options', ...


3

Looking further into the WooCommerce source, they fortunately, provide a filter named woocommerce_product_data_tabs which will allow you to conditional unset tabs. I've provided an example below: add_filter('woocommerce_product_data_tabs', function($tabs) { /** * The available tab array keys are: * * general * inventory * ...


3

i currently work on a woocommerce v2.1.12 shop and it seems they chaged that behavior. my ajax url to add items to the cart has to look like this: ?add-to-cart=[PRODUCT-ID]&variation_id=[VARIATION-ID]&attribute_[ATTRIBUTE-NAME]=[ATTRIBUTE-SLUG]&attribute_[ATTRIBUTE-NAME]=[ATTRIBUTE-SLUG] example: ...


3

Use get_current_blog_id() to check the current site. To run on site 2 only, use this: function new_meta_values($order_id) { if ( 2 !== get_current_blog_id() ) return; /* the rest of the function code */ }


3

While this question is probably technically off topic since it relates to woo, there's definitely some stuff that could be answered that will help other users in the future, plus, I really have been there with the multi-day frustration stuff and would have killed for a life line. There's a few things at play here, what you're looking at in the code you ...


3

Ok, worked it out via a little workaround. Add a new sorting function in Woocommerce, something like: https://gist.githubusercontent.com/bekarice/0df2b2d54d6ac8076f84/raw/wc-sort-by-postmeta.php works nicely, but remove the bit about meta values and keys since we're not sorting by custom fields (though that could be a good workaround too). Change the ...


3

The solution: $query = array( 'post_status' => 'publish', 'post_type' => 'product', 'posts_per_page' => 10, 'meta_query' => array( 'key' => '_price', 'value' => array(50, 100), 'compare' => 'BETWEEN', 'type' => 'NUMERIC' ), ); $wpquery = WP_Query($query); // return 10 products ...


2

You should be able to get the current product id using the using the $post global variable and use that with the WooCommerce function get_product() to the the product object and test its product type. public function __construct() { add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) ); } public function add_meta_box( $post_type ) { ...


2

WooCommerce Reviews is not a commenting board. You cannot create comment threads and reply to each other. I think I've found a very good solution for you. There is a free wordpress plugin which adds a new tub "Discussions" and opens powerful commenting board to do any type of discussions and comments on product page. This plugin name is "WooDiscuz". This is ...


2

You should be able to do this with the same filter that is talked about here. The full-size images are being kept by WordPress. It's not really a WooCommerce thing. As well as the settings for images in WooCommerce you will also need to set minimum image size in WordPress's Settings>Media... Then this script (see the link above for complete discussion) ...


2

i think this is what you need: $args = array( 'orderby' => 'name', 'hide_empty' => 1 ); $category_terms = get_terms( 'product_cat', $args ); foreach($category_terms as $cat_term){ echo $cat_term->name; } btw: woocommerce is offtopic here!


2

There is Woocommerce conditional tag for single product page Try if(is_product()) instead of if ( is_page_template( 'single-product.php' ))


2

In modern WordPress toolbar is considered mandatory part of admin. That is WordPress is explicitly opinionated about not letting you to disable it. While you still can kind of hack it out, it's unnecessary struggle. If you need a blank page there is no reason to struggle with blanking admin interface for it. You could simply use wp-admin/admin-post.php to ...


2

You need to delay the firing of your code, otherwise your conditionals will evaluate false (the request won't have been parsed yet). Use the action wp_enqueue_scripts: function wpse_182357_enqueue_scripts() { // Your code } add_action( 'wp_enqueue_scripts', 'wpse_182357_enqueue_scripts' ); Update: Missed the root of the problem - is_page_template() ...


2

Those options do not appear from the core but, they're are part of the Jetpack plugin. You should check with Jetpack files. Off-topic: I personally would prefer to disable these on Woocommerce pages. Hope this helps


2

If you define your own empty function, then it can cause a problem when the plugin tries to load its same function. The simplest way around this is to use PHP's built-in function_exists() method wrapped around the function call. If that function is defined (like inside the plugin) it'll run the call. If not, it's skips over it without a second thought. if ( ...


2

This is not that complicated, here is a code snippet that will get you started: if(is_user_logged_in()) { //We only need these products to check $products_to_check = array(81,82,83,84); $customer_bought = array(); //Get all orders made by the current user in the last 365 days $customer_orders = get_posts( apply_filters( ...


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

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 }


1

As per what I understood from your question, you want two things - Listing of all publisher Listing of all books of a particular publisher. Here is code for both. Listing of all publisher $terms = get_terms( 'pa_publisher' ); echo '<ul>'; foreach ($terms as $each_term) { echo '<li>'.$each_term->name.'</li>'; } echo ...


1

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


1

Try this - Add your button inside a form and write down script to add product to the cart and redirect user directly to the checkout page. Suppose, following is the button that you can put on single product page using a WooCommerce hook. <button name="checkout_now"> Checkout Now </button> PHP code: global $woocommerce; $post_id = ...


1

Arrrrg a WooCommerce question... quick burn him at the stake! There's a couple of problems with your callback function above: you are not declaring global $woocommerce so you do not have access to the $woocommerce global variable. and $woocommerce->customer holds the state of the WC_Customer class however this class does not contain a get_role() ...


1

Turns out it was the WooCommerce Jetpack Plugin all along. Stupid thing had something enabled which it didn't need. I guess that's what I get if I let a client access the plugin menu. Thank you, denis.stoyanov, for helping me find the solution!


1

Configure, product_id and parent_category_id according to your requirements. /* This is product id */ $product_id = 1; /* This is the id of the parent category */ $parent_category_id = 8; $cats = get_categories ( array ( 'type' => 'product', 'parent' => $parent_category_id, 'orderby' => 'term_group', 'hide_empty' => true, ...



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