abstracts
6 months ago
admin
6 months ago
blocks
10 months ago
cli
7 months ago
customizer
6 months ago
data-stores
5 months ago
emails
6 months ago
export
1 year ago
gateways
5 months ago
import
11 months ago
integrations
2 years ago
interfaces
1 year ago
legacy
1 year ago
libraries
1 year ago
log-handlers
1 year ago
payment-tokens
5 years ago
product-usage
1 year ago
queue
4 years ago
react-admin
6 months ago
rest-api
6 months ago
shipping
6 months ago
shortcodes
10 months ago
theme-support
2 years ago
tracks
6 months ago
traits
5 years ago
walkers
5 years ago
wccom-site
9 months ago
widgets
6 months ago
class-wc-ajax.php
6 months ago
class-wc-auth.php
1 year ago
class-wc-autoloader.php
7 months ago
class-wc-background-emailer.php
5 years ago
class-wc-background-updater.php
5 years ago
class-wc-brands-brand-settings-manager.php
1 year ago
class-wc-brands-coupons.php
1 year ago
class-wc-brands.php
6 months ago
class-wc-breadcrumb.php
5 years ago
class-wc-cache-helper.php
7 months ago
class-wc-cart-fees.php
2 years ago
class-wc-cart-session.php
6 months ago
class-wc-cart-totals.php
10 months ago
class-wc-cart.php
7 months ago
class-wc-checkout.php
1 year ago
class-wc-cli.php
9 months ago
class-wc-comments.php
9 months ago
class-wc-countries.php
7 months ago
class-wc-coupon.php
6 months ago
class-wc-customer-download-log.php
5 years ago
class-wc-customer-download.php
1 year ago
class-wc-customer.php
9 months ago
class-wc-data-exception.php
8 years ago
class-wc-data-store.php
3 years ago
class-wc-datetime.php
4 years ago
class-wc-deprecated-action-hooks.php
2 years ago
class-wc-deprecated-filter-hooks.php
3 years ago
class-wc-discounts.php
10 months ago
class-wc-download-handler.php
1 year ago
class-wc-emails.php
10 months ago
class-wc-embed.php
1 year ago
class-wc-form-handler.php
6 months ago
class-wc-frontend-scripts.php
6 months ago
class-wc-geo-ip.php
7 months ago
class-wc-geolite-integration.php
6 years ago
class-wc-geolocation.php
1 year ago
class-wc-https.php
2 years ago
class-wc-install.php
6 months ago
class-wc-integrations.php
5 years ago
class-wc-log-levels.php
2 years ago
class-wc-logger.php
1 year ago
class-wc-meta-data.php
4 years ago
class-wc-order-factory.php
2 years ago
class-wc-order-item-coupon.php
4 years ago
class-wc-order-item-fee.php
1 year ago
class-wc-order-item-meta.php
4 years ago
class-wc-order-item-product.php
7 months ago
class-wc-order-item-shipping.php
1 year ago
class-wc-order-item-tax.php
4 years ago
class-wc-order-item.php
7 months ago
class-wc-order-query.php
4 years ago
class-wc-order-refund.php
1 year ago
class-wc-order.php
6 months ago
class-wc-payment-gateways.php
7 months ago
class-wc-payment-tokens.php
3 years ago
class-wc-post-data.php
6 months ago
class-wc-post-types.php
1 year ago
class-wc-privacy-background-process.php
1 year ago
class-wc-privacy-erasers.php
9 months ago
class-wc-privacy-exporters.php
4 years ago
class-wc-privacy.php
11 months ago
class-wc-product-attribute.php
4 years ago
class-wc-product-download.php
2 years ago
class-wc-product-external.php
1 year ago
class-wc-product-factory.php
1 year ago
class-wc-product-grouped.php
10 months ago
class-wc-product-query.php
1 year ago
class-wc-product-simple.php
10 months ago
class-wc-product-variable.php
10 months ago
class-wc-product-variation.php
1 year ago
class-wc-query.php
6 months ago
class-wc-rate-limiter.php
4 years ago
class-wc-regenerate-images-request.php
3 years ago
class-wc-regenerate-images.php
1 year ago
class-wc-register-wp-admin-settings.php
4 years ago
class-wc-rest-authentication.php
1 year ago
class-wc-rest-exception.php
5 years ago
class-wc-session-handler.php
7 months ago
class-wc-shipping-rate.php
11 months ago
class-wc-shipping-zone.php
5 years ago
class-wc-shipping-zones.php
6 months ago
class-wc-shipping.php
1 year ago
class-wc-shortcodes.php
1 year ago
class-wc-structured-data.php
6 months ago
class-wc-tax.php
10 months ago
class-wc-template-loader.php
6 months ago
class-wc-tracker.php
7 months ago
class-wc-validation.php
2 years ago
class-wc-webhook.php
7 months ago
class-woocommerce.php
5 months ago
wc-account-functions.php
6 months ago
wc-attribute-functions.php
9 months ago
wc-brands-functions.php
1 year ago
wc-cart-functions.php
9 months ago
wc-conditional-functions.php
10 months ago
wc-core-functions.php
5 months ago
wc-coupon-functions.php
10 months ago
wc-deprecated-functions.php
9 months ago
wc-formatting-functions.php
6 months ago
wc-notice-functions.php
11 months ago
wc-order-functions.php
6 months ago
wc-order-item-functions.php
3 years ago
wc-order-step-logger-functions.php
6 months ago
wc-page-functions.php
1 year ago
wc-product-functions.php
7 months ago
wc-rest-functions.php
6 months ago
wc-stock-functions.php
6 months ago
wc-template-functions.php
7 months ago
wc-template-hooks.php
9 months ago
wc-term-functions.php
6 months ago
wc-update-functions.php
6 months ago
wc-user-functions.php
6 months ago
wc-webhook-functions.php
1 year ago
wc-widget-functions.php
5 years ago
wc-brands-functions.php
142 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Brands Helper Functions |
| 4 | * |
| 5 | * Important: For internal use only by the Automattic\WooCommerce\Internal\Brands package. |
| 6 | * |
| 7 | * @package WooCommerce |
| 8 | * @version 9.4.0 |
| 9 | */ |
| 10 | |
| 11 | declare( strict_types = 1); |
| 12 | |
| 13 | /** |
| 14 | * Helper function :: wc_get_brand_thumbnail_url function. |
| 15 | * |
| 16 | * @param int $brand_id Brand ID. |
| 17 | * @param string $size Thumbnail image size. |
| 18 | * @return string |
| 19 | */ |
| 20 | function wc_get_brand_thumbnail_url( $brand_id, $size = 'full' ) { |
| 21 | $thumbnail_id = get_term_meta( $brand_id, 'thumbnail_id', true ); |
| 22 | |
| 23 | if ( $thumbnail_id ) { |
| 24 | $thumb_src = wp_get_attachment_image_src( $thumbnail_id, $size ); |
| 25 | } |
| 26 | |
| 27 | return ! empty( $thumb_src ) ? current( $thumb_src ) : ''; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Helper function :: wc_get_brand_thumbnail_image function. |
| 32 | * |
| 33 | * @since 9.4.0 |
| 34 | * |
| 35 | * @param object $brand Brand term. |
| 36 | * @param string $size Thumbnail image size. |
| 37 | * @return string |
| 38 | */ |
| 39 | function wc_get_brand_thumbnail_image( $brand, $size = '' ) { |
| 40 | $thumbnail_id = get_term_meta( $brand->term_id, 'thumbnail_id', true ); |
| 41 | |
| 42 | if ( '' === $size || 'brand-thumb' === $size ) { |
| 43 | /** |
| 44 | * Filter the brand's thumbnail size. |
| 45 | * |
| 46 | * @since 9.4.0 |
| 47 | * |
| 48 | * @param string $size Brand's thumbnail size. |
| 49 | */ |
| 50 | $size = apply_filters( 'woocommerce_brand_thumbnail_size', 'shop_catalog' ); |
| 51 | } |
| 52 | |
| 53 | if ( $thumbnail_id ) { |
| 54 | $image_src = wp_get_attachment_image_src( $thumbnail_id, $size ); |
| 55 | $image_src = $image_src[0]; |
| 56 | $dimensions = wc_get_image_size( $size ); |
| 57 | $image_srcset = function_exists( 'wp_get_attachment_image_srcset' ) ? wp_get_attachment_image_srcset( $thumbnail_id, $size ) : false; |
| 58 | $image_sizes = function_exists( 'wp_get_attachment_image_sizes' ) ? wp_get_attachment_image_sizes( $thumbnail_id, $size ) : false; |
| 59 | } else { |
| 60 | $image_src = wc_placeholder_img_src(); |
| 61 | $dimensions = wc_get_image_size( $size ); |
| 62 | $image_srcset = false; |
| 63 | $image_sizes = false; |
| 64 | } |
| 65 | |
| 66 | // Add responsive image markup if available. |
| 67 | if ( $image_srcset && $image_sizes ) { |
| 68 | $image = '<img src="' . esc_url( $image_src ) . '" alt="' . esc_attr( $brand->name ) . '" class="brand-thumbnail" width="' . esc_attr( $dimensions['width'] ) . '" height="' . esc_attr( $dimensions['height'] ) . '" srcset="' . esc_attr( $image_srcset ) . '" sizes="' . esc_attr( $image_sizes ) . '" />'; |
| 69 | } else { |
| 70 | $image = '<img src="' . esc_url( $image_src ) . '" alt="' . esc_attr( $brand->name ) . '" class="brand-thumbnail" width="' . esc_attr( $dimensions['width'] ) . '" height="' . esc_attr( $dimensions['height'] ) . '" />'; |
| 71 | } |
| 72 | |
| 73 | return $image; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Retrieves product's brands. |
| 78 | * |
| 79 | * @param int $post_id Post ID (default: 0). |
| 80 | * @param string $sep Seperator (default: '). |
| 81 | * @param string $before Before item (default: ''). |
| 82 | * @param string $after After item (default: ''). |
| 83 | * @return array List of terms |
| 84 | */ |
| 85 | function wc_get_brands( $post_id = 0, $sep = ', ', $before = '', $after = '' ) { |
| 86 | global $post; |
| 87 | |
| 88 | if ( ! $post_id ) { |
| 89 | $post_id = $post->ID; |
| 90 | } |
| 91 | |
| 92 | return get_the_term_list( $post_id, 'product_brand', $before, $sep, $after ); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Polyfills for backwards compatibility with the WooCommerce Brands plugin. |
| 97 | */ |
| 98 | |
| 99 | if ( ! function_exists( 'get_brand_thumbnail_url' ) ) { |
| 100 | |
| 101 | /** |
| 102 | * Polyfill for get_brand_thumbnail_image. |
| 103 | * |
| 104 | * @param int $brand_id Brand ID. |
| 105 | * @param string $size Thumbnail image size. |
| 106 | * @return string |
| 107 | */ |
| 108 | function get_brand_thumbnail_url( $brand_id, $size = 'full' ) { |
| 109 | return wc_get_brand_thumbnail_url( $brand_id, $size ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if ( ! function_exists( 'get_brand_thumbnail_image' ) ) { |
| 114 | |
| 115 | /** |
| 116 | * Polyfill for get_brand_thumbnail_image. |
| 117 | * |
| 118 | * @param object $brand Brand term. |
| 119 | * @param string $size Thumbnail image size. |
| 120 | * @return string |
| 121 | */ |
| 122 | function get_brand_thumbnail_image( $brand, $size = '' ) { |
| 123 | return wc_get_brand_thumbnail_image( $brand, $size ); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | if ( ! function_exists( 'get_brands' ) ) { |
| 128 | |
| 129 | /** |
| 130 | * Polyfill for get_brands. |
| 131 | * |
| 132 | * @param int $post_id Post ID (default: 0). |
| 133 | * @param string $sep Seperator (default: '). |
| 134 | * @param string $before Before item (default: ''). |
| 135 | * @param string $after After item (default: ''). |
| 136 | * @return array List of terms |
| 137 | */ |
| 138 | function get_brands( $post_id = 0, $sep = ', ', $before = '', $after = '' ) { |
| 139 | return wc_get_brands( $post_id, $sep, $before, $after ); |
| 140 | } |
| 141 | } |
| 142 |