$taxonomy) { $name = $taxonomy instanceof WP_Taxonomy ? $taxonomy->name : $taxonomy; if(in_array($name, [Shop_Template::TAXONOMY, Detail_Template::TAXONOMY, Attribute_Template::TAXONOMY])) { unset($taxonomies[$index]); } } // Reset the indices. $taxonomies = array_values($taxonomies); } $taxonomies = apply_filters('aff_product_taxonomies', $taxonomies, $output, $only_custom); return $taxonomies; } /** * Get the product name. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return Name|null|string The name in the given output format. */ function aff_get_product_name($product_or_id = null, $output = 'scalar') { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return null; } $name = $product->get_name(); $name = apply_filters('aff_product_name', $name, $product); if(empty($name)) { return null; } if($output == 'scalar') { $name = $name->get_value(); } $name = apply_filters('aff_product_formatted_name', $name, $product, $output); return $name; } /** * Print the shop name. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param bool $escape Whether to escape the output or not. */ function aff_the_product_name($product_or_id = null, $escape = true) { $name = aff_get_product_name($product_or_id, 'scalar'); if($name == null) { return; } if($escape) { $name = esc_html($name); } echo $name; } /** * Check if the product has a review. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool */ function aff_has_product_review($product_or_id = null) { $review = aff_get_product_review($product_or_id, 'object'); return $review !== null; } /** * Get the product review. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "array" or "object". Default: "array". * @return null|array|Review The review in the given output format. */ function aff_get_product_review($product_or_id = null, $output = 'array') { $product = aff_get_product($product_or_id, 'object'); if($product instanceof Product_Variant) { $product = $product->get_parent(); } if(!($product instanceof Review_Aware_Interface)) { return null; } $review = $product->get_review(); if($review === null) { return null; } $review = apply_filters('aff_product_review', $review, $product); if($output == 'array') { $review = Review_Helper::to_array($review); } $review = apply_filters('aff_product_formatted_review', $review, $product, $output); return $review; } /** * Check if the product has a review rating. * * @since 0.8.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool */ function aff_has_product_review_rating($product_or_id = null) { $rating = aff_get_product_review_rating($product_or_id); return !empty($rating) || $rating === 0; } /** * Get the product review rating from 0 to 5. * * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return null|float|Rating The review rating in the given output format. */ function aff_get_product_review_rating($product_or_id = null, $output = 'scalar') { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return null; } $review = aff_get_product_review($product_or_id, 'object'); if($review === null) { return null; } $rating = $review->get_rating(); $rating = apply_filters('aff_product_review_rating', $rating, $review, $product); if($output == 'scalar') { $rating = $rating->get_value(); } $rating = apply_filters('aff_product_review_formatted_rating', $rating, $review, $product, $output); return $rating; } /** * Print the product review rating from 0 to 5 as stars. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output Either "scalar" or "html". Default: "scalar". * @param bool $escape Whether to escape the output or not. The output won't be escaped, if the output is "html". * @param string $full_star If the output is "html", you can provide some HTML used to render a "full star". * @param string $half_star If the output is "html", you can provide some HTML used to render a "half star". * @param string $no_star If the output is "html", you can provide some HTML used to render a "no star". */ function aff_the_product_review_rating($product_or_id = null, $output = 'scalar', $escape = true, $full_star = null, $half_star = null, $no_star = null) { // Deprecated 1.3: Make the function compatible with the equivalent before version 0.9.18. $num_args = func_num_args(); $args = func_get_args(); $allowed_outputs = ['scalar', 'html']; if(($num_args >= 2 && !in_array($args[1], $allowed_outputs))) { $args = func_get_args(); $full_star = $args[0]; $half_star = $args[1]; $no_star = $args[2]; $product_or_id = isset($args[3]) ? $args[3] : null; $output = 'html'; $escape = true; } $rating = aff_get_product_review_rating($product_or_id, 'scalar'); if(empty($rating) && $rating !== 0) { return; } if($output == 'scalar') { echo $escape ? esc_html($rating) : $rating; } else { for ($i = 0; $i < 5; $i++) { if ($rating >= ($i + 1)) { echo $full_star; } elseif ($rating >= ($i + 0.5)) { echo $half_star; } else { echo $no_star; } } } } /** * Check if the product has any review votes. * * @since 0.8.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool */ function aff_has_product_review_votes($product_or_id = null) { $votes = aff_get_product_review_votes($product_or_id, 'object'); return $votes !== null; } /** * Get the product review votes. * * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return null|int|Votes The product votes in the given output format. */ function aff_get_product_review_votes($product_or_id = null, $output = 'scalar') { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return null; } $review = aff_get_product_review($product, 'object'); if($review === null) { return null; } $votes = $review->get_votes(); if($votes === null) { return null; } $votes = apply_filters('aff_product_review_votes', $votes, $review, $product); if($output == 'scalar') { $votes = $votes->get_value(); } $votes = apply_filters('aff_product_review_formatted_votes', $votes, $review, $product, $output); return $votes; } /** * Print the product review votes. * * @since 0.9.22 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output Either "scalar" or "html". Default: "scalar". * @param bool $escape Whether to escape the output or not. */ function aff_the_product_review_votes($product_or_id = null, $output = 'scalar', $escape = true) { // Deprecated 1.3: Make the function compatible with the equivalent before version 0.9.22. $num_args = func_num_args(); $args = func_get_args(); $allowed_outputs = ['scalar', 'html']; if(($num_args == 2 && !in_array($args[1], $allowed_outputs))) { $args = func_get_args(); $product_or_id = isset($args[0]) ? $args[0] : null; $output = 'html'; $escape = isset($args[1]) ? $args[1] : null; } $votes = aff_get_product_review_votes($product_or_id, 'scalar'); if($votes === null) { return; } if($output == 'scalar') { echo $escape ? esc_html($votes) : $votes; } else { echo sprintf(_n( 'based on %s review', 'based on %s reviews', $votes, 'affilicious'), $escape ? esc_html($votes) : $votes ); } } /** * Get the plain product details of the detail groups. * * @since 0.3 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "array" or "object". Default: "array". * @return array|Detail[] The details in the given output format. */ function aff_get_product_details($product_or_id = null, $output = 'array') { $product = aff_get_product($product_or_id, 'object'); if($product instanceof Product_Variant) { $product = $product->get_parent(); } if(!($product instanceof Detail_Aware_Interface)) { return []; } $details = $product->get_details(); $details = apply_filters('aff_product_details', $details, $product); if(empty($details)) { return []; } if($output == 'array') { $details = array_map(function(Detail $detail) { return Detail_Helper::to_array($detail); }, $details); } $details = apply_filters('aff_product_formatted_details', $details, $product, $output); return $details; } /** * Check if the product has any details. * * @since 0.9.14 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product has details or not. */ function aff_has_product_details($product_or_id = null) { $details = aff_get_product_details($product_or_id, 'array'); return !empty($details); } /** * Check if the product has a thumbnail. * * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product has a thumbnail or not. */ function aff_has_product_thumbnail($product_or_id = null) { $thumbnail = aff_get_product_thumbnail($product_or_id, 'object'); return !empty($thumbnail); } /** * Get the thumbnail by the product. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Choose from "scalar", "array" or "object". Default: "scalar". * @return null|int|array|Image The image in the given output format. */ function aff_get_product_thumbnail($product_or_id = null, $output = 'array') { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return null; } $thumbnail = $product->get_thumbnail(); $thumbnail = apply_filters('aff_product_thumbnail', $thumbnail, $product); if(empty($thumbnail)) { return null; } if($output == 'scalar') { $thumbnail = $thumbnail->get_id(); } if($output == 'array') { $thumbnail = Image_Helper::to_array($thumbnail); } $thumbnail = apply_filters('aff_product_formatted_thumbnail', $thumbnail, $product, $output); return $thumbnail; } /** * Print the product thumbnail. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string|array $size Image size to use. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default value: 'post-thumbnail'. * @param string|array $attr Query string or array of attributes. Default value: ''. */ function aff_the_product_thumbnail($product_or_id = null, $size = 'post-thumbnail', $attr = '') { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return; } $thumbnail = get_the_post_thumbnail($product->get_id()->get_value(), $size, $attr); echo $thumbnail; } /** * Check if the product has an image gallery. * * @since 0.8.5 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool */ function aff_has_product_image_gallery($product_or_id = null) { $image_gallery = aff_get_product_image_gallery($product_or_id); return !empty($image_gallery); } /** * Get the image gallery by the product. * * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Choose from "scalar", "array" or "object". Default: "scalar". * @return int[]|array|Image[] The image of the image gallery in the given output format. */ function aff_get_product_image_gallery($product_or_id = null, $output = 'scalar') { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return []; } $images = $product->get_image_gallery(); if(empty($images)) { return []; } $images = apply_filters('aff_product_image_gallery', $images, $product); if($output == 'scalar') { $images = array_map(function(Image $image) { return $image->get_id(); }, $images); } if($output == 'array') { $images = array_map(function(Image $image) { return Image_Helper::to_array($image); }, $images); } $images = apply_filters('aff_product_formatted_image_gallery', $images, $product, $output); return $images; } /** * Check if the product has any shops. * * @since 0.7.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool */ function aff_has_product_shops($product_or_id = null) { $shops = aff_get_product_shops($product_or_id); return !empty($shops); } /** * Get the shops by the product. * * @since 0.3 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "array" or "object". Default: "array". * @return array|Shop[] The shop in the given output format. */ function aff_get_product_shops($product_or_id = null, $output = 'array') { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return []; } if ($product instanceof Complex_Product) { $product = $product->get_default_variant(); } if(!($product instanceof Shop_Aware_Interface)) { return []; } $shops = $product->get_shops(); if(empty($shops)) { return []; } $shops = apply_filters('aff_product_shops', $shops, $product); if($output == 'array') { $shops = array_map(function(Shop $shop) { return Shop_Helper::to_array($shop); }, $shops); } $shops = apply_filters('aff_product_formatted_shops', $shops, $product, $output); return $shops; } /** * Check if the product has any related products. * * @since 0.7.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool */ function aff_has_product_related_products($product_or_id = null) { $product_ids = aff_get_product_related_products($product_or_id); $result = !empty($product_ids); return $result; } /** * Get the related products by the product. * * @since 0.3 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return int[]|Product_Id[] The IDs of the related products in the given output format. */ function aff_get_product_related_products($product_or_id = null, $output = 'scalar') { $product = aff_get_product($product_or_id, 'object'); if(!($product instanceof Relation_Aware_Interface)) { return []; } $related_products = $product->get_related_products(); if(empty($related_products)) { return []; } $related_products = apply_filters('aff_product_related_products', $related_products, $product); if($output == 'scalar') { $related_products = array_map(function(Product_Id $related_product) { return $related_product->get_value(); }, $related_products); } $related_products = apply_filters('aff_product_formatted_related_products', $related_products, $product, $output); return $related_products; } /** * Get the query for the products. * * @since 0.7.1 * @param array $args * @return WP_Query */ function aff_get_products_query($args = array()) { // It's not allowed to set a custom post type. unset($args['post_type']); $options = wp_parse_args($args, array( 'post_type' => Product::POST_TYPE, 'order_by' => 'ASC', )); $query = new \WP_Query($options); return $query; } /** * Get the query of the related products by the product. * * @since 0.3 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param array $args * @return null|WP_Query */ function aff_get_product_related_products_query($product_or_id = null, $args = array()) { $related_product_ids = aff_get_product_related_products($product_or_id, 'scalar'); if (empty($related_product_ids)) { return null; } // It's not allowed to set a custom post type or use custom IDs. unset($args['post_type'], $args['post__in']); $options = wp_parse_args($args, array( 'post_type' => Product::POST_TYPE, 'post__in' => $related_product_ids, 'orderby' => 'post__in', 'order' => 'ASC' )); $query = new \WP_Query($options); return $query; } /** * Check if the product has any related accessories. * * @since 0.7.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool */ function aff_has_product_related_accessories($product_or_id = null) { $accessories = aff_get_product_related_accessories($product_or_id, 'objects'); $result = !empty($accessories); return $result; } /** * Get the related accessories by the product. * * @since 0.3 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return int[]|Product_Id[] The IDs of the related accessories in the given output format. */ function aff_get_product_related_accessories($product_or_id = null, $output = 'scalar') { $product = aff_get_product($product_or_id, 'object'); if($product === null || !($product instanceof Relation_Aware_Interface)) { return []; } $related_accessories = $product->get_related_accessories(); if(empty($related_accessories)) { return null; } $related_accessories = apply_filters('aff_product_related_accessories', $related_accessories, $product); if($output == 'scalar') { $related_accessories = array_map(function(Product_Id $related_accessory) { return $related_accessory->get_value(); }, $related_accessories); } $related_accessories = apply_filters('aff_product_formatted_related_accessories', $related_accessories, $product, $output); return $related_accessories; } /** * Get the query of the related accessories by the product. * * @since 0.3 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param array $args * @return null|WP_Query */ function aff_get_product_related_accessories_query($product_or_id = null, $args = array()) { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return null; } $related_accessories_ids = aff_get_product_related_accessories($product, 'scalar'); if (empty($related_accessories_ids)) { return null; } // It's not allowed to set a custom post type or use custom IDs. unset($args['post_type'], $args['post__in']); $options = wp_parse_args($args, array( 'post_type' => Product::POST_TYPE, 'post__in' => $related_accessories_ids, 'orderby' => 'post__in', 'order' => 'ASC' )); $query = new \WP_Query($options); return $query; } /** * Get the product link. * * @since 0.3 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return null|string The product link. */ function aff_get_product_link($product_or_id = null) { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return null; } $link = get_permalink($product->get_post()); if(empty($link)) { return null; } $link = apply_filters('aff_product_link', $link, $product); return $link; } /** * Print the product link. * * @since 0.8.8 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param bool $escape Whether to escape the output or not. */ function aff_the_product_link($product_or_id = null, $escape = true) { $link = aff_get_product_link($product_or_id); if($escape) { $link = esc_url($link); } echo $link; } /** * Check if the given product has any tags. * * @since 0.7.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool */ function aff_has_product_tags($product_or_id = null) { $tags = aff_get_product_tags($product_or_id, 'object'); return !empty($tags); } /** * Get the tags of the given product. * * @since 0.7.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return string[]|Tag[] The tags in the given output format. */ function aff_get_product_tags($product_or_id = null, $output = 'scalar') { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return []; } if($product instanceof Complex_Product) { $product = $product->get_default_variant(); } if(!($product instanceof Tag_Aware_Interface)) { return []; } $tags = $product->get_tags(); if(empty($tags)) { return []; } $tags = apply_filters('aff_product_tags', $tags, $product); if($output == 'scalar') { $tags = array_map(function(Tag $tag) { return $tag->get_value(); }, $tags); } $tags = apply_filters('aff_product_formatted_tags', $tags, $product, $output); return $tags; } /** * Print the tags of the given product. * * @since 0.7.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $before The html or string which is printed before every tag. * @param string $after The html or string which is printed after every tag. * @param bool $escape Whether to escape the output. */ function aff_the_product_tags($product_or_id = null, $before = '', $after = '', $escape = true) { $tags = aff_get_product_tags($product_or_id, 'scalar'); if(empty($tags)) { return; } foreach ($tags as $tag) { if($escape) { $tag = esc_html($tag); } echo $before . $tag . $after; } } /** * Get the shop of the given product. * * @since 0.3 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string|Affiliate_Link|null $affiliate_link If you pass in nothing as an affiliate link, the cheapest shop will be used. * @param string $output The required return type. Either "array" or "object". Default: "array". * @return null|array|Shop The shop in the given output format. */ function aff_get_product_shop($product_or_id = null, $affiliate_link = null, $output = 'array') { $product = aff_get_product($product_or_id, 'object'); if($product instanceof Complex_Product) { $product = $product->get_default_variant(); } if(!($product instanceof Shop_Aware_Interface)) { return null; } $shop = null; if($affiliate_link instanceof Affiliate_Link) { $shop = $product->get_shop($affiliate_link); } elseif ($affiliate_link === null) { $shop = $product->get_cheapest_shop(); } elseif (is_string($affiliate_link)) { $shop = $product->get_shop(new Affiliate_Link($affiliate_link)); } if($shop === null) { return null; } $cheapest = $affiliate_link === null; $shop = apply_filters('aff_product_shop', $shop, $product, $cheapest); if($output == 'array') { $shop = Shop_Helper::to_array($shop); } $shop = apply_filters('aff_product_formatted_shop', $shop, $product, $cheapest, $output); return $shop; } /** * Check if the product's cheapest shop has a price. * * @since 0.7.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product has a price or not. */ function aff_has_product_price($product_or_id = null) { $price = aff_get_product_price($product_or_id, 'object'); return $price !== null; } /** * Get the product's cheapest shop price. * * @since 0.3 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. One of "scalar", "array" or "object". Default: "scalar". * @return null|string|Money The price in the given output format. */ function aff_get_product_price($product_or_id = null, $output = 'scalar') { // Deprecated 1.3: Make the function compatible with the equivalent before version 0.9.18. $num_args = func_num_args(); $args = func_get_args(); $allowed_outputs = ['scalar', 'array', 'object']; if(($num_args == 2 && !in_array($args[1], $allowed_outputs))) { $args = func_get_args(); $product_or_id = $args[0]; $output = isset($args[2]) ? $args[2] : 'scalar'; } // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return null; } // Get the shop's price. $price = aff_get_shop_price($shop, $output); return $price; } /** * Print the product's cheapest shop price. * * @since 0.7.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param bool $escape Whether to escape the output or not. */ function aff_the_product_price($product_or_id = null, $escape = true) { // Deprecated 1.3: Make the function compatible with the equivalent before version 0.9.18. $num_args = func_num_args(); $args = func_get_args(); if(($num_args == 2 && !is_bool($args[1]))) { $args = func_get_args(); $product_or_id = $args[0]; $escape = isset($args[2]) ? $args[2] : true; } // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return; } // Print the shop's price. aff_the_shop_price($shop, $escape); } /** * Get the product's cheapest shop price value. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return string|null The price value in the given output format. */ function aff_get_product_price_value($product_or_id = null) { // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return null; } // Get the shop's price value. $value = aff_get_shop_price_value($shop); return $value; } /** * Print the product's cheapest shop price value. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param bool $escape Whether to escape the output or not. */ function aff_the_product_price_value($product_or_id = null, $escape = true) { // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return; } // Print the shop's price value. aff_the_shop_price_value($shop, $escape); } /** * Get the product's cheapest shop price currency. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. One of "symbol", "scalar" or "object". Default: "symbol". * @return string|Currency|null The price currency in the given output format or null. */ function aff_get_product_price_currency($product_or_id = null, $output = 'symbol') { // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return null; } // Get the shop's price currency. $currency = aff_get_shop_price_currency($shop, $output); return $currency; } /** * Print the product's cheapest shop price currency. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The printed currency type. Either "symbol" or "scalar". Default: symbol * @param bool $escape Whether to escape the output or not. */ function aff_the_product_price_currency($product_or_id = null, $output = 'symbol', $escape = true) { // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return; } // Print the shop's price currency. aff_the_shop_price_currency($shop, $output, $escape); } /** * Check if the product's cheapest shop has an old price. * * @since 0.8.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product has an old price or not. */ function aff_has_product_old_price($product_or_id = null) { $price = aff_get_product_old_price($product_or_id, 'object'); return $price !== null; } /** * Get the product's cheapest shop old price. * * @since 0.8.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. One of "scalar", "array" or "object". Default: "scalar". * @return null|string|Money The old price in the given output format. */ function aff_get_product_old_price($product_or_id = null, $output = 'scalar') { // Deprecated 1.3: Make the function compatible with the equivalent before version 0.9.18. $num_args = func_num_args(); $args = func_get_args(); $allowed_outputs = ['scalar', 'array', 'object']; if(($num_args == 2 && !in_array($args[1], $allowed_outputs))) { $args = func_get_args(); $product_or_id = $args[0]; $output = isset($args[2]) ? $args[2] : 'scalar'; } // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return null; } // Get the shop's old price. $price = aff_get_shop_price($shop, $output); return $price; } /** * Print the product's cheapest shop old price. * * @since 0.8.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param bool $escape Whether to escape the output or not. */ function aff_the_product_old_price($product_or_id = null, $escape = true) { // Deprecated 1.3: Make the function compatible with the equivalent before version 0.9.18. $num_args = func_num_args(); $args = func_get_args(); if(($num_args == 2 && !is_bool($args[1]))) { $args = func_get_args(); $product_or_id = $args[0]; $escape = isset($args[2]) ? $args[2] : true; } // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return; } // Print the shop's old price. aff_the_shop_old_price($shop, $escape); } /** * Get the product's cheapest shop old price value. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return string|null The old price value in the given output format. */ function aff_get_product_old_price_value($product_or_id = null) { // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return null; } // Get the shop's old price value. $value = aff_get_shop_old_price_value($shop); return $value; } /** * Print the product's cheapest shop old price value. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param bool $escape Whether to escape the output or not. */ function aff_the_product_old_price_value($product_or_id = null, $escape = true) { // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return; } // Print the shop's old price value. aff_the_shop_old_price_value($shop, $escape); } /** * Get the product's cheapest shop old price currency. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. One of "symbol", "scalar" or "object". Default: "symbol". * @return string|Currency|null The old price currency in the given output format or null. */ function aff_get_product_old_price_currency($product_or_id = null, $output = 'symbol') { // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return null; } // Get the shop's old price currency. $currency = aff_get_shop_old_price_currency($shop, $output); return $currency; } /** * Print the product's cheapest shop old price currency. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The printed currency type. Either "symbol" or "scalar". Default: symbol * @param bool $escape Whether to escape the output or not. */ function aff_the_product_old_price_currency($product_or_id = null, $output = 'symbol', $escape = true) { // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return; } // Print the shop's old price currency. aff_the_shop_old_price_currency($shop, $output, $escape); } /** * Get the product's availability based on the underlying shops. * * @since 0.9.22 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return string|Availability */ function aff_get_product_availability($product_or_id = null, $output = 'scalar') { $product = aff_get_product($product_or_id, 'object'); $availability = Availability::out_of_stock(); if($product instanceof Simple_Product || $product instanceof Product_Variant) { $shops = $product->get_shops(); foreach ($shops as $shop) { $availability = aff_get_shop_availability($shop, 'object'); if($availability->is_available()) { $availability = Availability::available(); break; } } } if ($product instanceof Complex_Product) { $product_variants = $product->get_variants(); foreach ($product_variants as $product_variant) { $availability = aff_get_product_availability($product_variant, 'object'); if($availability->is_available()) { $availability = Availability::available(); break; } } } if($output == 'scalar') { $availability = $availability->get_value(); } return $availability; } /** * Check if the product is available based on the underlying shops. * * @since 0.9.22 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product is available or not. */ function aff_is_product_available($product_or_id = null) { $availability = aff_get_product_availability($product_or_id, 'object'); $is_available = $availability->is_available(); return $is_available; } /** * Check if the product is out of stock based on the underlying shops. * * @since 0.9.22 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product is out of stock or not. */ function aff_is_product_out_of_stock($product_or_id = null) { $availability = aff_get_product_availability($product_or_id, 'object'); $is_out_of_stock = $availability->is_out_of_stock(); return $is_out_of_stock; } /** * Get the product's cheapest shop affiliate product ID. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return string|Affiliate_Product_Id|null The product affiliate link in the given output format. */ function aff_get_product_affiliate_product_id($product_or_id = null, $output = 'scalar') { // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return null; } // Get the shop's affiliate product ID. $affiliate_product_id = aff_get_shop_affiliate_product_id($shop, $output); return $affiliate_product_id; } /** * Print the product's cheapest shop affiliate product ID. * * @since 0.9.18 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param bool $escape Whether to escape the output or not. */ function aff_the_product_affiliate_product_id($product_or_id = null, $escape = true) { // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return; } // Get the shop's affiliate product ID. aff_the_shop_affiliate_product_id($shop, $escape); } /** * Get the product's cheapest shop affiliate link. * * @since 0.3 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return string|Affiliate_Link|null The product affiliate link in the given output format. */ function aff_get_product_affiliate_link($product_or_id = null, $output = 'scalar') { // Deprecated 1.3: Make the function compatible with the equivalent before version 0.9.18. $num_args = func_num_args(); $args = func_get_args(); $allowed_outputs = ['scalar', 'array', 'object']; if(($num_args == 2 && !in_array($args[1], $allowed_outputs))) { $args = func_get_args(); $product_or_id = $args[0]; $output = isset($args[2]) ? $args[2] : 'scalar'; } // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return null; } // Get the shop's affiliate link. $affiliate_link = aff_get_shop_affiliate_link($shop, $output); return $affiliate_link; } /** * Print the product's cheapest shop affiliate link. * * @since 0.8.8 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param bool $escape Whether to escape the output or not. */ function aff_the_product_affiliate_link($product_or_id = null, $escape = true) { // Deprecated 1.3: Make the function compatible with the equivalent before version 0.9.18. $num_args = func_num_args(); $args = func_get_args(); if(($num_args == 2 && !is_bool($args[1]))) { $args = func_get_args(); $product_or_id = $args[0]; $escape = isset($args[2]) ? $args[2] : true; } // Get the product's shop. $shop = aff_get_product_shop($product_or_id, null, 'object'); if(empty($shop)) { return; } // Get the shop's affiliate link. aff_the_shop_affiliate_link($shop, $escape); } /** * Check if the product is of the given type. * * @since 0.9 * @param string|Type $type * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product is of the type or not. */ function aff_is_product_type($type, $product_or_id = null) { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return false; } if(!($type instanceof Type)) { $type = new Type($type); } $result = $product->get_type()->is_equal_to($type); $result = apply_filters('aff_is_product_type', $result, $product, $type); return $result; } /** * Check if the product is a simple product. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product is of simple type or not. */ function aff_is_product_simple($product_or_id = null) { $result = aff_is_product_type(Type::simple(), $product_or_id); return $result; } /** * Check if the product is a complex product. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product is of complex type or not. */ function aff_is_product_complex($product_or_id = null) { $result = aff_is_product_type(Type::complex(), $product_or_id); return $result; } /** * Check if the product is a product variant. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product is of variant type or not. */ function aff_is_product_variant($product_or_id = null) { $result = aff_is_product_type(Type::variant(), $product_or_id); return $result; } /** * Get the parent of the product variant. * If the given product is already the parent, it will be returned instead. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "array" or "object". Default: "array". * @return null|array|Product The complex parent product of the given product variant. */ function aff_get_product_variant_parent($product_or_id = null, $output = 'array') { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return null; } if($product instanceof Product_Variant) { $product = $product->get_parent(); } if(!($product instanceof Complex_Product)) { return null; } if($output == 'array') { $product = Product_Helper::to_array($product); } return $product; } /** * Check if the given parent complex product contains the variants * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @param int|string|array|\WP_Post|Product|Product_Id|null $variant_or_id If you pass in nothing as a product variant, the default variant will be used. * @return bool Whether the complex parent product has the variant or not. */ function aff_has_product_variant($complex_or_id = null, $variant_or_id = null) { $product_variant = aff_get_product_variant($complex_or_id, $variant_or_id, 'object'); $result = $product_variant !== null; return $result; } /** * Get the product variant by the complex parent product. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @param int|string|array|\WP_Post|Product|Product_Id|null $variant_or_id If you pass in nothing as a product variant, the default variant will be used. * @param string $output The required return type. Either "array" or "object". Default: "array". * @return null|array|Product_Variant The product variant in the given output format. */ function aff_get_product_variant($complex_or_id = null, $variant_or_id = null, $output = 'array') { $complex_product = aff_get_product($complex_or_id, 'object'); if(!($complex_product instanceof Complex_Product)) { return null; } $product_variant = aff_get_product($variant_or_id, 'object'); if(!($product_variant instanceof Product_Variant)) { return null; } $product_variant = $complex_product->get_variant($product_variant->get_slug()); if($product_variant === null) { return null; } $product_variant = apply_filters('aff_product_variant', $product_variant, $complex_product); if($output == 'array') { $product_variant = Product_Helper::to_array($product_variant); } $product_variant = apply_filters('aff_product_formatted_variant', $product_variant, $complex_product, $output); return $product_variant; } /** * Check if the given product has any variants. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @return bool Whether the complex parent product has some variants or not. */ function aff_has_product_variants($complex_or_id = null) { $product_variants = aff_get_product_variants($complex_or_id, 'object'); $result = !empty($product_variants); return $result; } /** * Get the product variants of the given product. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @param string $output The required return type. Either "array" or "object". Default: "array". * @return array|Product_Variant[] All product variants of the given complex parent product in the given output format. */ function aff_get_product_variants($complex_or_id = null, $output = 'array') { $complex_product = aff_get_product($complex_or_id, 'object'); if(!($complex_product instanceof Complex_Product)) { return []; } $product_variants = $complex_product->get_variants(); if(empty($product_variants)) { return []; } $product_variants = apply_filters('aff_product_variants', $product_variants, $complex_product); if($output == 'array') { $product_variants = array_map(function(Product_Variant $product_variant) { return Product_Helper::to_array($product_variant); }, $product_variants); } $product_variants = apply_filters('aff_product_formatted_variants', $product_variants, $complex_product, $output); return $product_variants; } /** * Get the default variant of the given product. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @param string $output The required return type. Either "array" or "object". Default: "array". * @return null|array|Product_Variant The product variant in the given output format. */ function aff_get_product_default_variant($complex_or_id = null, $output = 'array') { $complex_product = aff_get_product($complex_or_id, 'object'); if(!($complex_product instanceof Complex_Product)) { return null; } $product_variant = $complex_product->get_default_variant(); if($product_variant === null) { return null; } $product_variant = apply_filters('aff_product_default_variant', $product_variant, $complex_product); if($output == 'array') { $product_variant = Product_Helper::to_array($product_variant); } $product_variant = apply_filters('aff_product_formatted_default_variant', $product_variant, $complex_product, $output); return $product_variant; } /** * Check if the given variant is the default one of the complex parent product. * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @param int|string|array|\WP_Post|Product|Product_Id|null $variant_or_id If you pass in nothing as a product variant, the default variant will be used. * @return bool Whether the product variant is the default variant of the complex parent product or not. */ function aff_is_product_default_variant($complex_or_id = null, $variant_or_id = null) { $complex_product = aff_get_product($complex_or_id, 'object'); if(!($complex_product instanceof Complex_Product)) { return false; } $product_variant = aff_get_product($variant_or_id, 'object'); if(!($complex_product instanceof Product_Variant)) { return false; } $default_variant = aff_get_product_default_variant($complex_product, 'object'); $result = $product_variant->is_equal_to($default_variant); $result = apply_filters('aff_is_product_default_variant', $result, $complex_product, $product_variant); return $result; } /** * Get the attributes of the product variant * * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param int|string|array|\WP_Post|Product|Product_Id|null $variant_or_id If you pass in nothing as a product variant, the default variant will be used. * @param string $output The required return type. Either "array" or "object". Default: "array". * @return array|Attribute[] The attribute in the given output format. */ function aff_get_product_variant_attributes($product_or_id = null, $variant_or_id = null, $output = 'array') { $complex_product = aff_get_product($product_or_id, 'object'); if($complex_product instanceof Product_Variant) { $complex_product = $complex_product->get_parent(); } if(!($complex_product instanceof Complex_Product)) { return []; } $product_variant = null; if($variant_or_id === null) { $product_variant = $complex_product->get_default_variant(); } else { $product_variant = aff_get_product_variant($complex_product, $variant_or_id, 'object'); } if($product_variant === null) { return []; } $attributes = $product_variant->get_attributes(); $attributes = apply_filters('aff_product_variant_attributes', $attributes, $complex_product, $product_variant); if($output == 'array') { $attributes = array_map(function(Attribute $attribute) { return Attribute_Helper::to_array($attribute); }, $attributes); } $attributes = apply_filters('aff_product_variant_formatted_attributes', $attributes, $complex_product, $product_variant, $output); return $attributes; } /** * Check if the product attribute choices are enabled for the variant switching. * * @since 0.9.14 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product attribute choices are enabled for the product or not. */ function aff_has_product_attribute_choices($product_or_id = null) { $product_attribute_choices = aff_get_product_attribute_choices($product_or_id); if(empty($product_attribute_choices)) { return false; } return true; } /** * Get the product attributes choices for the variant switching. * * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return array The attribute choices for the variant switching. */ function aff_get_product_attribute_choices($product_or_id = null) { // Current product $product = aff_get_product($product_or_id, 'object'); if($product === null) { return []; } // Parent product $parent = aff_get_product_variant_parent($product, 'object'); if($parent === null) { return []; } // Product variants $variants = aff_get_product_variants($parent, 'object'); if($variants === null) { return []; } // Current attribute if($product instanceof Product_Variant) { $current_attributes = aff_get_product_variant_attributes($parent, $product, 'array'); } elseif($product instanceof Complex_Product) { $current_attributes = aff_get_product_variant_attributes($product, null, 'array'); } if(empty($current_attributes)) { return []; } // Create the basic choices without permalinks and display $choices = array(); foreach ($variants as $variant) { if(!$variant->has_id()) { continue; } $attributes = aff_get_product_variant_attributes($product, $variant, 'array'); if(empty($attributes)) { continue; } foreach ($attributes as $index => $attribute) { if(!isset($choices[$attribute['slug']])) { $choices[$attribute['slug']] = array( 'name' => $attribute['name'], 'slug' => $attribute['slug'], 'attributes' => array(), ); } // Get the previous and next index $next_index = $index + 1 < count($attributes) ? $index + 1 : $index; $prev_index = $index - 1 >= 0 ? $index - 1 : 0; $display = 'unreachable'; if($attribute['value'] == $current_attributes[$index]['value']) { $display = 'selected'; } if ($display == 'unreachable' && ( ($index !== $prev_index && $attributes[$prev_index]['value'] == $current_attributes[$prev_index]['value']) || ($index !== $next_index && $attributes[$next_index]['value'] == $current_attributes[$next_index]['value']))) { $display = 'reachable'; } if( !isset($choices[$attribute['slug']]['attributes'][$attribute['value']]) || ($display == 'selected' && $choices[$attribute['slug']]['attributes'][$attribute['value']]['display'] != 'selected') || ($display == 'reachable' && $choices[$attribute['slug']]['attributes'][$attribute['value']]['display'] == 'unreachable')) { $choices[$attribute['slug']]['attributes'][$attribute['value']] = array( 'value' => $attribute['value'], 'unit' => $attribute['unit'], 'display' => $display, 'permalink' => $display == 'selected' ? null : get_permalink($variant->get_post()), ); } } } // Remove the keys $choices = array_values($choices); foreach ($choices as $index => $choice) { $choices[$index]['attributes'] = array_values($choices[$index]['attributes']); } $choices = apply_filters('aff_product_attribute_choices', $choices, $parent); return $choices; } /** * Prints the product attributes choices for the variant switching. * * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. */ function aff_the_product_attribute_choices($product_or_id = null) { $product = aff_get_product($product_or_id); if($product === null) { return; } aff_render_template('product/attribute-choices', [ 'product' => $product, ]); } /** * Get the shop name. * * @since 0.9 * @param array|Shop $shop Whether to escape the output or not. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return null|string|Name The name in the given output format. */ function aff_get_shop_name($shop, $output = 'scalar') { // Normalize the shop. if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } $name = $shop->get_name(); $name = apply_filters('aff_shop_name', $name, $shop); if(empty($name)) { return null; } if($output == 'scalar') { $name = $name->get_value(); } $name = apply_filters('aff_shop_formatted_name', $name, $shop, $output); return $name; } /** * Print the shop name. * * @since 0.9 * @param array|Shop $shop The shop from which the name is taken. * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_name($shop = null, $escape = true) { $name = aff_get_shop_name($shop, 'scalar'); if($name == null) { return; } if($escape) { $name = esc_html($name); } echo $name; } /** * Check if the shop has a thumbnail. * * @since 0.9 * @param array|Shop $shop The shop from which the thumbnail is taken. * @return bool Whether the shop has a thumbnail or not. */ function aff_has_shop_thumbnail($shop = null) { $thumbnail = aff_get_shop_thumbnail($shop, 'object'); $result = !empty($thumbnail); return $result; } /** * Get the shop thumbnail. * If you pass in nothing as a parameter, the current post will be used. * * @since 0.9 * @param array|Shop $shop The shop from which the thumbnail is taken. * @param string $output The required return type. Choose from "scalar", "array" or "object". Default: "scalar". * @return null|int|array|Image The image in the given output format. */ function aff_get_shop_thumbnail($shop, $output = 'array') { // Normalize the shop. if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } $thumbnail = $shop->get_thumbnail(); $thumbnail = apply_filters('aff_shop_thumbnail', $thumbnail, $shop); if(empty($thumbnail)) { return null; } if($output == 'scalar') { $thumbnail = $thumbnail->get_id(); } if($output == 'array') { $thumbnail = Image_Helper::to_array($thumbnail); } $thumbnail = apply_filters('aff_shop_formatted_thumbnail', $thumbnail, $shop, $output); return $thumbnail; } /** * Print the shop thumbnail. * If you pass in nothing as a parameter, the current post will be used. * * @since 0.9 * @param array|Shop $shop * @param string|array $size Image size to use. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default value: 'post-thumbnail'. * @param string|array $attr Query string or array of attributes. Default value: ''. */ function aff_the_shop_thumbnail($shop, $size = 'thumbnail', $attr = '') { $thumbnail = aff_get_shop_thumbnail($shop, 'scalar'); if(empty($thumbnail)) { return; } $result = wp_get_attachment_image($thumbnail, $size, false, $attr); echo $result; } /** * Get the price indication like VAT and shipping costs of the shop. * * @since 0.7 * @param null|array|Shop $shop The shop from which the price indication is taken. * @return string The shop price indication containing the VAT and shipping costs. */ function aff_get_shop_price_indication($shop = null) { // Normalize the shop. if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } $text = $shop !== null && $shop->has_price_indication() ? $shop->get_price_indication()->get_value() : Price_Indication::standard(); $text = apply_filters('aff_shop_price_indication', $text, $shop); return $text; } /** * Print the price indication like VAT and shipping costs of the shop. * * @since 0.7 * @param array|Shop $shop The shop from which the price indication is taken. * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_price_indication($shop = null, $escape = true) { $indication = aff_get_shop_price_indication($shop); if($indication === null) { return; } if($escape) { $indication = esc_html($indication); } echo $indication; } /** * Check if the shop has an updated at price indication. * * @since 0.8.12 * @param array|Shop $shop The shop from which the price indication is taken. * @return bool Whether the shop has a updated at indication or not. */ function aff_has_shop_updated_at_indication($shop) { return !empty(aff_get_shop_updated_at_indication($shop)); } /** * Get the last updated indication of the shop. * * @since 0.7 * @param array|Shop $shop The shop from which the updated at indication is taken. * @param null|string $custom_text Custom text to show instead the default indication. * @return null|string The shop updated at indication containing the date and time of the last update. */ function aff_get_shop_updated_at_indication($shop, $custom_text = null) { // Normalize the shop. if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } $text = null; if($shop !== null) { $updated_at = Time_Helper::to_datetime_i18n($shop->get_updated_at()); $text = sprintf( !empty($custom_text) ? $custom_text : __('Last updated: %s.', 'affilicious'), $updated_at ); } $text = apply_filters('aff_shop_updated_at_indication', $text, $shop); return $text; } /** * Print the last updated indication for the shop. * * @since 0.7 * @param array|Shop $shop The shop from which the updated at indication is taken. * @param null|string $custom_text Custom text to show instead the default indication. Use "%s" as placeholder for the formatted date and time. * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_updated_at_indication($shop, $custom_text = null, $escape = true) { $indication = aff_get_shop_updated_at_indication($shop, $custom_text); if($indication === null) { return; } if($escape) { $indication = esc_html($indication); } echo $indication; } /** * Get the shop's availability. * * @since 0.9 * @param array|Shop $shop The shop from which the availability is taken. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return string|Availability */ function aff_get_shop_availability($shop, $output = 'scalar') { if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } if(empty($shop)) { $availability = Availability::out_of_stock(); } else { $availability = $shop->get_pricing()->get_availability(); } $availability = apply_filters('aff_shop_availability', $availability, $shop); if($output == 'scalar') { $availability = $availability->get_value(); } $availability = apply_filters('aff_shop_formatted_availability', $availability, $shop, $output); return $availability; } /** * Check if the shop is available. * * @since 0.7 * @param array|Shop $shop The shop from which the availability is taken. * @return bool Whether the shop is available or not. */ function aff_is_shop_available($shop) { // Normalize the shop. if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } if(empty($shop)) { return false; } $available = $shop->get_pricing()->get_availability()->is_available(); $available = apply_filters('aff_is_shop_available', $available, $shop); return $available; } /** * Check if the shop is out of stock. * * @since 0.9 * @param array|Shop $shop The shop from which the availability is taken. * @return bool Whether the shop is out of stock or not. */ function aff_is_shop_out_of_stock($shop) { // Normalize the shop. if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } $out_of_stock = $shop->get_pricing()->get_availability()->is_out_of_stock(); $out_of_stock = apply_filters('aff_is_shop_out_of_stock', $out_of_stock, $shop); return $out_of_stock; } /** * Check if the shop contains a price. * * @since 0.9 * @param array|Shop $shop The shop from which the price is taken. * @return bool Whether the shop contains a price or not. */ function aff_has_shop_price($shop) { return !empty(aff_get_shop_price($shop)); } /** * Get the shop's price. * * @since 0.8.9 * @param array|Shop $shop The shop from which the price is taken. * @param string $output The required return type. One of "scalar", "array" or "object". Default: "scalar". * @return null|string|array|Money The price in the given output format. */ function aff_get_shop_price($shop, $output = 'scalar') { // Convert to an object to standardize the filter arguments, if it's an array. if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } // Check if there is a shop. if(empty($shop)) { return null; } // Get the shop's price. $price = $shop->get_pricing()->get_price(); $price = apply_filters('aff_shop_price', $price, $shop); // Check if there is a price. if($price === null) { return null; } // Convert the price into the desired output format. if($output == 'scalar') { $price = Money_Helper::to_string($price); } elseif ($output == 'array') { $price = Money_Helper::to_array($price); } $price = apply_filters('aff_shop_formatted_price', $price, $shop, $output); return $price; } /** * Print the formatted shop's price. * * @since 0.8.9 * @param array|Shop $shop The shop from which the price is taken. * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_price($shop, $escape = true) { $price = aff_get_shop_price($shop, 'scalar'); if(empty($price)) { return; } if($escape) { $price = esc_html($price); } echo $price; } /** * Get the shop's price value. * * @since 0.9.18 * @param array|Shop $shop The shop from which the price value is taken. * @return string|null The price value in the given output format. */ function aff_get_shop_price_value($shop) { // Get the shop's price. $price = aff_get_shop_price($shop, 'object'); if(empty($price)) { return null; } $value = $price->get_value(); $value= apply_filters('aff_shop_price_value', $value, $shop, $price); $value = apply_filters('aff_shop_price_formatted_value', $value, $shop, $price); return $value; } /** * Print the shop's price value. * * @since 0.9.18 * @param array|Shop $shop The shop from which the price value is taken. * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_price_value($shop, $escape = true) { $value = aff_get_shop_price_value($shop); if(empty($value) && floatval($value) !== 0) { return; } if($escape) { $value = esc_html($value); } echo $value; } /** * Get the shop's price currency. * * @since 0.9.18 * @param array|Shop $shop The shop from which the price currency is taken. * @param string $output The required return type. One of "symbol", "scalar" or "object". Default: "symbol". * @return string|Currency|null The price currency in the given output format or null. */ function aff_get_shop_price_currency($shop, $output = 'symbol') { // Get the shop's price. $price = aff_get_shop_price($shop, 'object'); if(empty($price)) { return null; } // Get the price's currency. $currency = $price->get_currency(); $currency = apply_filters('aff_shop_price_currency', $currency, $shop, $price); // Convert the currency into the desired output format. if($output == 'scalar') { $currency = $currency->get_value(); } elseif ($output == 'symbol') { $currency = $currency->get_symbol(); } $currency = apply_filters('aff_shop_price_formatted_currency', $currency, $shop, $price, $output); return $currency; } /** * Print the shop's price currency. * * @since 0.9.18 * @param array|Shop $shop The shop from which the price currency is taken. * @param string $output The printed currency type. Either "symbol" or "scalar". Default: symbol * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_price_currency($shop, $output = 'symbol', $escape = true) { $currency = aff_get_shop_price_currency($shop, $output); if(empty($currency)) { return; } if($escape) { $currency = esc_html($currency); } echo $currency; } /** * Check if the shop contains an old price. * * @since 0.9 * @param array|Shop $shop The shop from which the old price is taken. * @return bool Whether the shop contains a old price or not. */ function aff_has_shop_old_price($shop) { return !empty(aff_get_shop_old_price($shop)); } /** * Get the shop's old price. * * @since 0.8.9 * @param array|Shop $shop The shop from which the old price is taken. * @param string $output The required return type. One of "scalar", "array" or "object". Default: "scalar". * @return null|string|array|Money The old price in the given output format. */ function aff_get_shop_old_price($shop, $output = 'scalar') { // Convert to an object to standardize the filter arguments, if it's an array. if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } // Check if there is a shop. if(empty($shop)) { return null; } // Get the shop's old price. $old_price = $shop->get_pricing()->get_old_price(); $old_price = apply_filters('aff_shop_old_price', $old_price, $shop); // Check if there is an old price. if($old_price === null) { return null; } // Convert the old price into the desired output format. if($output == 'scalar') { $old_price = Money_Helper::to_string($old_price); } elseif($output == 'array') { $old_price = Money_Helper::to_array($old_price); } $old_price = apply_filters('aff_shop_formatted_old_price', $old_price, $shop, $output); return $old_price; } /** * Get the shop's old price value. * * @since 0.9.18 * @param array|Shop $shop The shop from which the old price value is taken. * @return string|null The price value in the given output format. */ function aff_get_shop_old_price_value($shop) { // Get the shop's old price. $old_price = aff_get_shop_old_price($shop, 'object'); if(empty($old_price)) { return null; } $value = $old_price->get_value(); $value = apply_filters('aff_shop_old_price_value', $value, $shop, $old_price); $value = apply_filters('aff_shop_old_price_formatted_value', $value, $shop, $old_price); return $value; } /** * Print the shop's price value. * * @since 0.9.18 * @param array|Shop $shop The shop from which the price value is taken. * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_old_price_value($shop, $escape = true) { $value = aff_get_shop_old_price_value($shop); if(empty($value) && floatval($value) !== 0) { return; } if($escape) { $value = esc_html($value); } echo $value; } /** * Get the shop's price currency. * * @since 0.9.18 * @param array|Shop $shop The shop from which the price currency is taken. * @param string $output The required return type. One of "symbol", "scalar" or "object". Default: "symbol". * @return string|Currency|null The price currency in the given output format or null. */ function aff_get_shop_old_price_currency($shop, $output = 'symbol') { // Get the shop's old price. $old_price = aff_get_shop_old_price($shop, 'object'); if(empty($old_price)) { return null; } // Get the old price's currency. $currency = $old_price->get_currency(); $currency = apply_filters('aff_shop_old_price_currency', $currency, $shop, $old_price); // Convert the currency into the desired output format. if($output == 'scalar') { $currency = $currency->get_value(); } elseif ($output == 'symbol') { $currency = $currency->get_symbol(); } $currency = apply_filters('aff_shop_old_price_formatted_currency', $currency, $shop, $old_price, $output); return $currency; } /** * Print the shop's price currency. * * @since 0.9.18 * @param array|Shop $shop The shop from which the price currency is taken. * @param string $output The printed currency type. Either "symbol" or "scalar". Default: symbol * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_old_price_currency($shop, $output = 'symbol', $escape = true) { $currency = aff_get_shop_old_price_currency($shop, $output); if(empty($currency)) { return; } if($escape) { $currency = esc_html($currency); } echo $currency; } /** * Get the shop's affiliate link. * * @since 0.9 * @param array|Shop $shop The shop from which the affiliate link is taken. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return string|Affiliate_Link */ function aff_get_shop_affiliate_link($shop, $output = 'scalar') { // Convert to an object to standardize the filter arguments, if it's an array. if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } // Check if there is a shop. if(empty($shop)) { return null; } // Get the shop's affiliate link. $affiliate_link = $shop->get_tracking()->get_affiliate_link(); $affiliate_link = apply_filters('aff_shop_affiliate_link', $affiliate_link, $shop); // Convert the affiliate link into the desired output format. if($output == 'scalar') { $affiliate_link = $affiliate_link->get_value(); } $affiliate_link = apply_filters('aff_shop_formatted_affiliate_link', $affiliate_link, $shop, $output); return $affiliate_link; } /** * Print the shop's affiliate link. * * @since 0.9 * @param array|Shop $shop The shop from which the affiliate link is taken. * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_affiliate_link($shop, $escape = true) { $affiliate_link = aff_get_shop_affiliate_link($shop, 'scalar'); if(empty($affiliate_link)) { return; } if($escape) { $affiliate_link = esc_html($affiliate_link); } echo $affiliate_link; } /** * Get the shop's affiliate product ID. * * @since 0.9.18 * @param array|Shop $shop The shop from which the affiliate product ID is taken. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return string|Affiliate_Product_Id|null The affiliate product ID in the given output format or null. */ function aff_get_shop_affiliate_product_id($shop, $output = 'scalar') { // Convert to an object to standardize the filter arguments, if it's an array. if(is_array($shop)) { $shop = Shop_Helper::from_array($shop); } // Check if there is a shop. if(empty($shop)) { return null; } // Get the shop's affiliate product ID. $affiliate_product_id = $shop->get_tracking()->get_affiliate_product_id(); $affiliate_product_id = apply_filters('aff_shop_affiliate_product_id', $affiliate_product_id, $shop); // Check if there is an affiliate product ID. if($affiliate_product_id === null) { return null; } // Convert the affiliate product ID into the desired output format. if($output == 'scalar') { $affiliate_product_id = $affiliate_product_id->get_value(); } $affiliate_product_id = apply_filters('aff_shop_formatted_affiliate_product_id', $affiliate_product_id, $shop, $output); return $affiliate_product_id; } /** * Print the shop's affiliate product ID. * * @since 0.9.18 * @param array|Shop $shop The shop from which the affiliate product ID is taken. * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_affiliate_product_id($shop, $escape = true) { $affiliate_product_id = aff_get_shop_affiliate_product_id($shop, 'scalar'); if(empty($affiliate_product_id)) { return; } if($escape) { $affiliate_product_id = esc_html($affiliate_product_id); } echo $affiliate_product_id; } /** * Print the formatted shop's old price. * * @since 0.8.9 * @param array|Shop $shop The shop from which old price is taken. * @param bool $escape Whether to escape the output or not. */ function aff_the_shop_old_price($shop, $escape = true) { $old_price = aff_get_shop_old_price($shop, 'scalar'); if(empty($old_price)) { return; } if($escape) { $old_price = esc_html($old_price); } echo $old_price; } /** * Get the license key for the item. * * @since 0.8.12 * @param string $item_key The item key of the software. * @return null|string */ function aff_get_license_key($item_key) { /** @var \Affilicious\Common\License\License_Manager $license_manager */ $license_manager = Affilicious::get('affilicious.common.admin.license.manager'); $license_key = $license_manager->find_item_license_key($item_key); if($license_key === null) { return null; } $license_key = apply_filters('aff_license_key', $license_key, $item_key); return $license_key; } /** * Print the license key item. * * @since 0.8.12 * @param string $item_key The item key of the software. * @param bool $escape Whether to escape the output or not. */ function aff_the_license_key($item_key, $escape = true) { $license_key = aff_get_license_key($item_key); if($escape) { $license_key = esc_html($license_key); } echo $license_key; } /** * Check if the license status is valid. * * @since 0.8.12 * @param License_Status $status The status of the license processor. * @return bool */ function aff_is_license_status_active(License_Status $status) { return $status->is_valid(); } /** * Check if the license status is valid. * * @since 0.8.12 * @param License_Status $status The status of the license processor. * @return bool */ function aff_is_license_status_inactive(License_Status $status) { return $status->is_invalid(); } /** * Check if the license status is missing. * * @since 0.8.12 * @param License_Status $status The status of the license processor. * @return bool */ function aff_is_license_status_missing(License_Status $status) { return $status->is_missing(); } /** * Check if the license status is success. * * @since 0.8.12 * @param License_Status $status The status of the license processor. * @return bool */ function aff_is_license_status_success(License_Status $status) { return $status->is_success(); } /** * Check if the license status is error. * * @since 0.8.12 * @param License_Status$status The status of the license processor. * @return bool */ function aff_is_license_status_error(License_Status $status) { return $status->is_error(); } /** * Check if the license status has a message. * * @since 0.8.12 * @param License_Status $status The status of the license processor. * @return bool */ function aff_has_license_status_message(License_Status $status) { return $status->has_message(); } /** * Get the license status message. * * @since 0.8.12 * @param License_Status $status The status of the license processor. * @return null|string The license status message. */ function aff_get_license_status_message(License_Status $status) { $message = $status->get_message(); if($message === null) { return null; } $message = apply_filters('aff_license_status_message', $message, $status); return $message; } /** * Print the license status message. * * @since 0.8.12 * @param License_Status $status The status of the license processor. * @param bool $escape Whether to escape the output or not. */ function aff_the_license_status_message(License_Status $status, $escape = true) { $message = aff_get_license_status_message($status); if($message === null) { return; } if($escape) { $message = esc_html($message); } echo $message; } /** * Render the template immediately. * * @since 0.9.5 * @param string $name The name for the template. * @param array $params The variables for the template. Default: empty array. * @param bool $require Whether to require or require. Default: true. */ function aff_render_template($name, $params = [], $require = true) { Template_Helper::render($name, $params, $require); } /** * Buffers the rendered template into a string. * * @since 0.9.5 * @param string $name The name for the template. * @param array $params The variables for the template. Default: empty array. * @param bool $require Whether to require or require. Default: true. * @return string The buffered and rendered template. */ function aff_stringify_template($name, $params = [], $require = true) { return Template_Helper::stringify($name, $params, $require); } /** * Get the buy button text for the product universal box. * * @since 0.9.10 * @param null|array $shop The shop from which the data is taken. * @return string The buy button text. */ function aff_get_product_universal_box_buy_button_text($shop = null) { $text = get_theme_mod('aff_universal_box-shops-button_buy_text'); if(empty($text)) { $text = __('Buy now at %s', 'affilicious'); } if(isset($shop['name']) && strpos($text, '%s') !== false) { $text = sprintf($text, $shop['name']); } return $text; } /** * Print the buy button text for the product universal box. * * @since 0.9.10 * @param null|array $shop The shop from which the data is taken. * @param bool $escape Whether to escape the output or not. */ function aff_the_product_universal_box_buy_button_text($shop = null, $escape = true) { $text = aff_get_product_universal_box_buy_button_text($shop); if($escape) { $text = esc_html($text); } echo $text; } /** * Get the not available button text for the product universal box. * * @since 0.9.10 * @param null|array $shop The shop from which the data is taken. * @return string The not available button text. */ function aff_get_product_universal_box_not_available_button_text($shop = null) { $text = get_theme_mod('aff_universal_box-shops-button_not_available_text'); if(empty($text)) { return __('Unfortunately not available', 'affilicious'); } if(isset($shop['name']) && strpos($text, '%s') !== false) { $text = sprintf($text, $shop['name']); } return $text; } /** * Print the not available button text for the product universal box. * * @since 0.9.10 * @param null|array $shop The shop from which the data is taken. * @param bool $escape Whether to escape the output or not. */ function aff_the_product_universal_box_not_available_button_text($shop = null, $escape = true) { $text = aff_get_product_universal_box_not_available_button_text($shop); if($escape) { $text = esc_html($text); } echo $text; } /** * Check if the notice with the ID is dismissed. * * @since 0.9.16 * @param string $dismissible_id The unique ID used for the notice. * @return bool Whether the notice is dismissed or not. */ function aff_is_notice_dismissed($dismissible_id) { $option = get_option("aff_notice_{$dismissible_id}_dismissed"); $is_dismissed = $option == 'yes'; return $is_dismissed; } // ========== DEPRECATED - Don't use anymore ========== /** * Get the affiliate link by the product and shop. * * @deprecated 1.1 Use 'aff_the_product_affiliate_link' instead. * @since 0.5.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "scalar" or "object". Default: "scalar". * @return null|string|Affiliate_Link The cheapest affiliate link in the given output format. */ function aff_get_product_cheapest_affiliate_link($product_or_id = null, $output = 'scalar') { $product = aff_get_product($product_or_id, 'object'); if($product === null) { return null; } $shop = aff_get_product_cheapest_shop($product, 'object'); if($shop === null) { return null; } $affiliate_link = aff_get_product_affiliate_link($product, 'object'); if($affiliate_link === null) { return null; } if($output == 'scalar') { $affiliate_link = $affiliate_link->get_value(); } return $affiliate_link; } /** * Check if the product is of the given type. * * @deprecated 1.1 Use 'aff_is_product_type' instead. * @since 0.6 * @param string|Type $type * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product is of the type or not. */ function aff_product_is_type($type, $product_or_id = null) { return aff_is_product_type($type, $product_or_id); } /** * Check if the product is a simple product. * * @deprecated 1.1 Use 'aff_is_product_simple' instead. * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product is of simple type or not. */ function aff_product_is_simple($product_or_id = null) { return aff_is_product_simple($product_or_id); } /** * Check if the product is a complex product. * * @deprecated 1.1 Use 'aff_is_product_complex' instead. * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product is of complex type or not. */ function aff_product_is_complex($product_or_id = null) { return aff_is_product_complex($product_or_id); } /** * Check if the product is a product variant. * * @deprecated 1.1 Use 'aff_is_product_variant' instead * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return bool Whether the product is of variant type or not. */ function aff_product_is_variant($product_or_id = null) { return aff_is_product_variant($product_or_id); } /** * Get the parent of the product variant. * If the given product is already the parent, it will be returned instead. * * @deprecated 1.1 Use 'aff_get_product_variant_parent' instead * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @return null|Product The complex parent product of the given product variant. */ function aff_product_get_parent($product_or_id = null) { return aff_get_product_variant_parent($product_or_id, 'object'); } /** * Get the cheapest price with the currency of the product. * * @deprecated 1.1 Use 'aff_get_product_price' instead. * @since 0.5.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. One of "scalar", "array" or "object". Default: "scalar". * @return null|string|Money The cheapest price in the given output format. */ function aff_get_product_cheapest_price($product_or_id = null, $output = 'scalar') { return aff_get_product_price($product_or_id, $output); } /** * Check if the given parent complex product contains the variants * * @deprecated 1.1 Use 'aff_has_product_variant' instead * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @param int|string|array|\WP_Post|Product|Product_Id|null $variant_or_id If you pass in nothing as a product variant, the default variant will be used. * @return bool Whether the complex parent product has the variant or not. */ function aff_product_has_variant($complex_or_id = null, $variant_or_id = null) { return aff_has_product_variant($complex_or_id, $variant_or_id); } /** * Get the product variant by the complex parent product. * * @deprecated 1.1 Use 'aff_get_product_variant' instead * @since 0.8 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @param int|string|array|\WP_Post|Product|Product_Id|null $variant_or_id If you pass in nothing as a product variant, the default variant will be used. * @return null|Product_Variant The product variant as an object. */ function aff_product_get_variant($complex_or_id = null, $variant_or_id = null) { return aff_get_product_variant($complex_or_id, $variant_or_id, 'object'); } /** * Check if the given product has any variants. * * @deprecated 1.1 Use 'aff_has_product_variants' instead * @since 0.7.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @return bool Whether the complex parent product has some variants or not. */ function aff_product_has_variants($complex_or_id = null) { return aff_has_product_variants($complex_or_id); } /** * Get the product variants of the given product. * * @deprecated 1.1 Use 'aff_get_product_variants' instead. * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @return Product_Variant[] All product variants of the given complex parent product. */ function aff_product_get_variants($complex_or_id = null) { return aff_get_product_variants($complex_or_id, 'object'); } /** * Get the cheapest old price with the currency of the product. * * @deprecated 1.1 Use 'aff_get_product_old_price' instead. * @since 0.9 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. One of "scalar", "array" or "object". Default: "scalar". * @return null|string|Money The cheapest old price in the given output format. */ function aff_get_product_cheapest_old_price($product_or_id = null, $output = 'scalar') { return aff_get_product_old_price($product_or_id, $output); } /** * Get the default variant of the given product. * * @deprecated 1.1 Use 'aff_get_product_default_variant' instead * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @return null|Product_Variant The product variant or null, */ function aff_product_get_default_variant($complex_or_id = null) { return aff_get_product_default_variant($complex_or_id, 'object'); } /** * Check if the given variant is the default one * * @deprecated 1.1 Use 'aff_is_product_default_variant' instead * @since 0.6 * @param int|string|array|\WP_Post|Product|Product_Id|null $complex_or_id If you pass in nothing as a complex product, the current post will be used. * @param int|string|array|\WP_Post|Product|Product_Id|null $variant_or_id If you pass in nothing as a product variant, the default variant will be used. * @return bool Whether the product variant is the default variant of the complex parent product or not. */ function aff_product_is_default_variant($complex_or_id = null, $variant_or_id = null) { $result = aff_is_product_default_variant($complex_or_id, $variant_or_id); return $result; } /** * Get the attributes of the product variant * * @deprecated 1.1 Use 'aff_get_product_variant_attributes' instead * @since 0.8 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param int|string|array|\WP_Post|Product|Product_Id|null $variant_or_id If you pass in nothing as a product variant, the default variant will be used. * @return array The attributes. */ function aff_product_get_variant_attributes($product_or_id = null, $variant_or_id = null) { return aff_get_product_variant_attributes($product_or_id, $variant_or_id, 'array'); } /** * Check if the shop should display the old price. * * @deprecated 1.1 Don't use it anymore. * @since 0.8 * @return bool */ function aff_should_shop_display_old_price() { return true; } /** * Get the cheapest shop of the given product. * * @deprecated 1.1 Use 'aff_get_product_shop' instead. * @since 0.5.1 * @param int|string|array|\WP_Post|Product|Product_Id|null $product_or_id If you pass in nothing as a parameter, the current post will be used. * @param string $output The required return type. Either "array" or "object". Default: "array". * @return null|array|Shop The shop in the given output format. */ function aff_get_product_cheapest_shop($product_or_id = null, $output = 'array') { return aff_get_product_shop($product_or_id, null, $output); }