This repository has been archived by the owner on May 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Index Woo-Commerce Product Prices #529
Labels
Comments
You can indeed push additional attributes by following the example here. Here are some common WooCommerce attributes you might be interested in: <?php
$product = wc_get_product( $post );
// Extract prices.
$variations_count = 0;
if ( $product instanceof WC_Product_Variable ) {
$price = $product->get_variation_price( 'min', true );
$regular_price = $product->get_variation_regular_price( 'min', true );
$sale_price = $product->get_variation_sale_price( 'min', true );
$max_price = $product->get_variation_price( 'max', true );
$variations_count = count( $product->get_available_variations() );
} else {
$price = $max_price = $product->get_display_price();
$regular_price = $product->get_display_price( $product->get_regular_price() );
$sale_price = $product->get_display_price( $product->get_sale_price() );
}
$attributes['product_type'] = (string) $product->get_type();
$attributes['price'] = (float) $price;
$attributes['regular_price'] = (float) $regular_price;
$attributes['sale_price'] = (float) $sale_price;
$attributes['max_price'] = (float) $max_price;
$attributes['is_on_sale'] = (bool) $product->is_on_sale();
$attributes['average_rating'] = (float) $product->get_average_rating();
$attributes['rating_count'] = (int) $product->get_rating_count();
$attributes['attributes'] = (array) $product->get_attributes();
$attributes['width'] = (string) $product->get_width();
$attributes['height'] = (string) $product->get_height();
$attributes['weight'] = (string) $product->get_weight();
$attributes['length'] = (string) $product->get_length();
$attributes['review_count'] = (int) $product->get_review_count();
$attributes['dimensions'] = (string) $product->get_dimensions();
$attributes['variations_count'] = $variations_count;
$attributes['is_featured'] = $product->is_featured() ? 1 : 0;
$attributes['sku'] = $product->get_sku();
$attributes['total_sales'] = (int) get_post_meta( $post->ID, 'total_sales', true ); |
Is it possible that this will not index price attribute on products that are out of stock? It seems to be 0 on all products that are out of stock. |
Unsure @Jurero123 , but it might have to do with WC3 vs WC2. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Plugins indexes everything of product post type except price tags.
Is there any way to Index Regular and Sale prices per product?
The text was updated successfully, but these errors were encountered: