This commit is contained in:
Tiago Noronha 2018-07-06 16:36:19 +01:00
parent 9970f1799a
commit fda124147b
1 changed files with 58 additions and 42 deletions

View File

@ -451,7 +451,6 @@ add_action( 'woocommerce_scheduled_sales', 'wc_scheduled_sales' );
/** /**
* Get attachment image attributes. * Get attachment image attributes.
* *
* @access public
* @param array $attr Image attributes. * @param array $attr Image attributes.
* @return array * @return array
*/ */
@ -467,7 +466,6 @@ add_filter( 'wp_get_attachment_image_attributes', 'wc_get_attachment_image_attri
/** /**
* Prepare attachment for JavaScript. * Prepare attachment for JavaScript.
* *
* @access public
* @param array $response JS version of a attachment post object. * @param array $response JS version of a attachment post object.
* @return array * @return array
*/ */
@ -528,12 +526,14 @@ add_action( 'template_redirect', 'wc_track_product_view', 20 );
* @return array * @return array
*/ */
function wc_get_product_types() { function wc_get_product_types() {
return (array) apply_filters( 'product_type_selector', array( return (array) apply_filters(
'simple' => __( 'Simple product', 'woocommerce' ), 'product_type_selector', array(
'grouped' => __( 'Grouped product', 'woocommerce' ), 'simple' => __( 'Simple product', 'woocommerce' ),
'external' => __( 'External/Affiliate product', 'woocommerce' ), 'grouped' => __( 'Grouped product', 'woocommerce' ),
'variable' => __( 'Variable product', 'woocommerce' ), 'external' => __( 'External/Affiliate product', 'woocommerce' ),
) ); 'variable' => __( 'Variable product', 'woocommerce' ),
)
);
} }
/** /**
@ -763,12 +763,14 @@ function wc_get_product_attachment_props( $attachment_id = null, $product = fals
* @return array * @return array
*/ */
function wc_get_product_visibility_options() { function wc_get_product_visibility_options() {
return apply_filters( 'woocommerce_product_visibility_options', array( return apply_filters(
'visible' => __( 'Shop and search results', 'woocommerce' ), 'woocommerce_product_visibility_options', array(
'catalog' => __( 'Shop only', 'woocommerce' ), 'visible' => __( 'Shop and search results', 'woocommerce' ),
'search' => __( 'Search results only', 'woocommerce' ), 'catalog' => __( 'Shop only', 'woocommerce' ),
'hidden' => __( 'Hidden', 'woocommerce' ), 'search' => __( 'Search results only', 'woocommerce' ),
) ); 'hidden' => __( 'Hidden', 'woocommerce' ),
)
);
} }
/** /**
@ -874,10 +876,12 @@ function wc_get_related_products( $product_id, $limit = 5, $exclude_ids = array(
$limit = $limit >= -1 ? $limit : 5; $limit = $limit >= -1 ? $limit : 5;
$exclude_ids = array_merge( array( 0, $product_id ), $exclude_ids ); $exclude_ids = array_merge( array( 0, $product_id ), $exclude_ids );
$transient_name = 'wc_related_' . $product_id; $transient_name = 'wc_related_' . $product_id;
$query_args = http_build_query( array( $query_args = http_build_query(
'limit' => $limit, array(
'exclude_ids' => $exclude_ids, 'limit' => $limit,
) ); 'exclude_ids' => $exclude_ids,
)
);
$transient = get_transient( $transient_name ); $transient = get_transient( $transient_name );
$related_posts = $transient && isset( $transient[ $query_args ] ) ? $transient[ $query_args ] : false; $related_posts = $transient && isset( $transient[ $query_args ] ) ? $transient[ $query_args ] : false;
@ -905,10 +909,12 @@ function wc_get_related_products( $product_id, $limit = 5, $exclude_ids = array(
set_transient( $transient_name, $transient, DAY_IN_SECONDS ); set_transient( $transient_name, $transient, DAY_IN_SECONDS );
} }
$related_posts = apply_filters( 'woocommerce_related_products', $related_posts, $product_id, array( $related_posts = apply_filters(
'limit' => $limit, 'woocommerce_related_products', $related_posts, $product_id, array(
'excluded_ids' => $exclude_ids, 'limit' => $limit,
) ); 'excluded_ids' => $exclude_ids,
)
);
shuffle( $related_posts ); shuffle( $related_posts );
@ -937,10 +943,12 @@ function wc_get_product_term_ids( $product_id, $taxonomy ) {
* @return float * @return float
*/ */
function wc_get_price_including_tax( $product, $args = array() ) { function wc_get_price_including_tax( $product, $args = array() ) {
$args = wp_parse_args( $args, array( $args = wp_parse_args(
'qty' => '', $args, array(
'price' => '', 'qty' => '',
) ); 'price' => '',
)
);
$price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : $product->get_price(); $price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : $product->get_price();
$qty = '' !== $args['qty'] ? max( 0.0, (float) $args['qty'] ) : 1; $qty = '' !== $args['qty'] ? max( 0.0, (float) $args['qty'] ) : 1;
@ -997,10 +1005,12 @@ function wc_get_price_including_tax( $product, $args = array() ) {
* @return float * @return float
*/ */
function wc_get_price_excluding_tax( $product, $args = array() ) { function wc_get_price_excluding_tax( $product, $args = array() ) {
$args = wp_parse_args( $args, array( $args = wp_parse_args(
'qty' => '', $args, array(
'price' => '', 'qty' => '',
) ); 'price' => '',
)
);
$price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : $product->get_price(); $price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : $product->get_price();
$qty = '' !== $args['qty'] ? max( 0.0, (float) $args['qty'] ) : 1; $qty = '' !== $args['qty'] ? max( 0.0, (float) $args['qty'] ) : 1;
@ -1034,23 +1044,29 @@ function wc_get_price_excluding_tax( $product, $args = array() ) {
* @return float * @return float
*/ */
function wc_get_price_to_display( $product, $args = array() ) { function wc_get_price_to_display( $product, $args = array() ) {
$args = wp_parse_args( $args, array( $args = wp_parse_args(
'qty' => 1, $args, array(
'price' => $product->get_price(), 'qty' => 1,
) ); 'price' => $product->get_price(),
)
);
$price = $args['price']; $price = $args['price'];
$qty = $args['qty']; $qty = $args['qty'];
return 'incl' === get_option( 'woocommerce_tax_display_shop' ) ? return 'incl' === get_option( 'woocommerce_tax_display_shop' ) ?
wc_get_price_including_tax( $product, array( wc_get_price_including_tax(
'qty' => $qty, $product, array(
'price' => $price, 'qty' => $qty,
) ) : 'price' => $price,
wc_get_price_excluding_tax( $product, array( )
'qty' => $qty, ) :
'price' => $price, wc_get_price_excluding_tax(
) ); $product, array(
'qty' => $qty,
'price' => $price,
)
);
} }
/** /**