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.
*
* @access public
* @param array $attr Image attributes.
* @return array
*/
@ -467,7 +466,6 @@ add_filter( 'wp_get_attachment_image_attributes', 'wc_get_attachment_image_attri
/**
* Prepare attachment for JavaScript.
*
* @access public
* @param array $response JS version of a attachment post object.
* @return array
*/
@ -528,12 +526,14 @@ add_action( 'template_redirect', 'wc_track_product_view', 20 );
* @return array
*/
function wc_get_product_types() {
return (array) apply_filters( 'product_type_selector', array(
'simple' => __( 'Simple product', 'woocommerce' ),
'grouped' => __( 'Grouped product', 'woocommerce' ),
'external' => __( 'External/Affiliate product', 'woocommerce' ),
'variable' => __( 'Variable product', 'woocommerce' ),
) );
return (array) apply_filters(
'product_type_selector', array(
'simple' => __( 'Simple product', 'woocommerce' ),
'grouped' => __( 'Grouped 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
*/
function wc_get_product_visibility_options() {
return apply_filters( 'woocommerce_product_visibility_options', array(
'visible' => __( 'Shop and search results', 'woocommerce' ),
'catalog' => __( 'Shop only', 'woocommerce' ),
'search' => __( 'Search results only', 'woocommerce' ),
'hidden' => __( 'Hidden', 'woocommerce' ),
) );
return apply_filters(
'woocommerce_product_visibility_options', array(
'visible' => __( 'Shop and search results', 'woocommerce' ),
'catalog' => __( 'Shop only', '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;
$exclude_ids = array_merge( array( 0, $product_id ), $exclude_ids );
$transient_name = 'wc_related_' . $product_id;
$query_args = http_build_query( array(
'limit' => $limit,
'exclude_ids' => $exclude_ids,
) );
$query_args = http_build_query(
array(
'limit' => $limit,
'exclude_ids' => $exclude_ids,
)
);
$transient = get_transient( $transient_name );
$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 );
}
$related_posts = apply_filters( 'woocommerce_related_products', $related_posts, $product_id, array(
'limit' => $limit,
'excluded_ids' => $exclude_ids,
) );
$related_posts = apply_filters(
'woocommerce_related_products', $related_posts, $product_id, array(
'limit' => $limit,
'excluded_ids' => $exclude_ids,
)
);
shuffle( $related_posts );
@ -937,10 +943,12 @@ function wc_get_product_term_ids( $product_id, $taxonomy ) {
* @return float
*/
function wc_get_price_including_tax( $product, $args = array() ) {
$args = wp_parse_args( $args, array(
'qty' => '',
'price' => '',
) );
$args = wp_parse_args(
$args, array(
'qty' => '',
'price' => '',
)
);
$price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : $product->get_price();
$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
*/
function wc_get_price_excluding_tax( $product, $args = array() ) {
$args = wp_parse_args( $args, array(
'qty' => '',
'price' => '',
) );
$args = wp_parse_args(
$args, array(
'qty' => '',
'price' => '',
)
);
$price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : $product->get_price();
$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
*/
function wc_get_price_to_display( $product, $args = array() ) {
$args = wp_parse_args( $args, array(
'qty' => 1,
'price' => $product->get_price(),
) );
$args = wp_parse_args(
$args, array(
'qty' => 1,
'price' => $product->get_price(),
)
);
$price = $args['price'];
$qty = $args['qty'];
return 'incl' === get_option( 'woocommerce_tax_display_shop' ) ?
wc_get_price_including_tax( $product, array(
'qty' => $qty,
'price' => $price,
) ) :
wc_get_price_excluding_tax( $product, array(
'qty' => $qty,
'price' => $price,
) );
wc_get_price_including_tax(
$product, array(
'qty' => $qty,
'price' => $price,
)
) :
wc_get_price_excluding_tax(
$product, array(
'qty' => $qty,
'price' => $price,
)
);
}
/**