Skip to content
This repository has been archived by the owner. It is now read-only.

Index Woo-Commerce Product Prices #529

Closed
curiouscosmos opened this issue Mar 25, 2017 · 3 comments
Closed

Index Woo-Commerce Product Prices #529

curiouscosmos opened this issue Mar 25, 2017 · 3 comments
Labels

Comments

@curiouscosmos
Copy link

@curiouscosmos curiouscosmos commented Mar 25, 2017

Plugins indexes everything of product post type except price tags.
Is there any way to Index Regular and Sale prices per product?

@rayrutjes
Copy link
Member

@rayrutjes rayrutjes commented Mar 29, 2017

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

@rayrutjes rayrutjes added this to the 2.0.0 milestone Apr 25, 2017
@rayrutjes rayrutjes removed this from the 2.0.0 milestone Apr 25, 2017
@Jurero123
Copy link

@Jurero123 Jurero123 commented Nov 17, 2017

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.

@rayrutjes
Copy link
Member

@rayrutjes rayrutjes commented Nov 17, 2017

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.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants