abstracts
11 months ago
admin
10 months ago
blocks
1 year ago
cli
11 months ago
customizer
11 months ago
data-stores
11 months ago
emails
11 months ago
export
1 year ago
gateways
11 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
11 months ago
rest-api
10 months ago
shipping
1 year ago
shortcodes
11 months ago
theme-support
2 years ago
tracks
1 year ago
traits
5 years ago
walkers
5 years ago
wccom-site
1 year ago
widgets
1 year ago
class-wc-ajax.php
11 months ago
class-wc-auth.php
1 year ago
class-wc-autoloader.php
1 year 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
10 months ago
class-wc-breadcrumb.php
5 years ago
class-wc-cache-helper.php
1 year ago
class-wc-cart-fees.php
2 years ago
class-wc-cart-session.php
11 months ago
class-wc-cart-totals.php
10 months ago
class-wc-cart.php
11 months ago
class-wc-checkout.php
1 year ago
class-wc-cli.php
1 year ago
class-wc-comments.php
11 months ago
class-wc-countries.php
1 year ago
class-wc-coupon.php
11 months ago
class-wc-customer-download-log.php
5 years ago
class-wc-customer-download.php
1 year ago
class-wc-customer.php
11 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
11 months ago
class-wc-download-handler.php
1 year ago
class-wc-emails.php
11 months ago
class-wc-embed.php
1 year ago
class-wc-form-handler.php
11 months ago
class-wc-frontend-scripts.php
1 year ago
class-wc-geo-ip.php
11 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
11 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
1 year ago
class-wc-order-item-shipping.php
1 year ago
class-wc-order-item-tax.php
4 years ago
class-wc-order-item.php
1 year ago
class-wc-order-query.php
4 years ago
class-wc-order-refund.php
1 year ago
class-wc-order.php
11 months ago
class-wc-payment-gateways.php
11 months ago
class-wc-payment-tokens.php
3 years ago
class-wc-post-data.php
1 year ago
class-wc-post-types.php
1 year ago
class-wc-privacy-background-process.php
1 year ago
class-wc-privacy-erasers.php
1 year 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
1 year ago
class-wc-product-query.php
1 year ago
class-wc-product-simple.php
1 year ago
class-wc-product-variable.php
1 year ago
class-wc-product-variation.php
1 year ago
class-wc-query.php
1 year 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
10 months ago
class-wc-shipping-rate.php
11 months ago
class-wc-shipping-zone.php
5 years ago
class-wc-shipping-zones.php
5 years ago
class-wc-shipping.php
1 year ago
class-wc-shortcodes.php
1 year ago
class-wc-structured-data.php
1 year ago
class-wc-tax.php
2 years ago
class-wc-template-loader.php
11 months ago
class-wc-tracker.php
11 months ago
class-wc-validation.php
2 years ago
class-wc-webhook.php
1 year ago
class-woocommerce.php
5 months ago
wc-account-functions.php
11 months ago
wc-attribute-functions.php
1 year ago
wc-brands-functions.php
1 year ago
wc-cart-functions.php
11 months ago
wc-conditional-functions.php
11 months ago
wc-core-functions.php
11 months ago
wc-coupon-functions.php
1 year ago
wc-deprecated-functions.php
1 year ago
wc-formatting-functions.php
11 months ago
wc-notice-functions.php
11 months ago
wc-order-functions.php
11 months ago
wc-order-item-functions.php
3 years ago
wc-order-step-logger-functions.php
1 year ago
wc-page-functions.php
1 year ago
wc-product-functions.php
11 months ago
wc-rest-functions.php
11 months ago
wc-stock-functions.php
1 year ago
wc-template-functions.php
11 months ago
wc-template-hooks.php
1 year ago
wc-term-functions.php
11 months ago
wc-update-functions.php
11 months ago
wc-user-functions.php
11 months ago
wc-webhook-functions.php
1 year ago
wc-widget-functions.php
5 years ago
class-wc-product-external.php
198 lines
| 1 | <?php |
| 2 | /** |
| 3 | * External Product |
| 4 | * |
| 5 | * External products cannot be bought; they link offsite. Extends simple products. |
| 6 | * |
| 7 | * @package WooCommerce\Classes\Products |
| 8 | * @version 3.0.0 |
| 9 | */ |
| 10 | |
| 11 | use Automattic\WooCommerce\Enums\ProductStockStatus; |
| 12 | use Automattic\WooCommerce\Enums\ProductType; |
| 13 | |
| 14 | defined( 'ABSPATH' ) || exit; |
| 15 | |
| 16 | /** |
| 17 | * Product external class. |
| 18 | */ |
| 19 | class WC_Product_External extends WC_Product { |
| 20 | |
| 21 | /** |
| 22 | * Stores product data. |
| 23 | * |
| 24 | * @var array |
| 25 | */ |
| 26 | protected $extra_data = array( |
| 27 | 'product_url' => '', |
| 28 | 'button_text' => '', |
| 29 | ); |
| 30 | |
| 31 | /** |
| 32 | * Get internal type. |
| 33 | * |
| 34 | * @return string |
| 35 | */ |
| 36 | public function get_type() { |
| 37 | return ProductType::EXTERNAL; |
| 38 | } |
| 39 | |
| 40 | /* |
| 41 | |-------------------------------------------------------------------------- |
| 42 | | Getters |
| 43 | |-------------------------------------------------------------------------- |
| 44 | | |
| 45 | | Methods for getting data from the product object. |
| 46 | */ |
| 47 | |
| 48 | /** |
| 49 | * Get product url. |
| 50 | * |
| 51 | * @param string $context What the value is for. Valid values are 'view' and 'edit'. |
| 52 | * @return string |
| 53 | */ |
| 54 | public function get_product_url( $context = 'view' ) { |
| 55 | return esc_url_raw( $this->get_prop( 'product_url', $context ) ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Get button text. |
| 60 | * |
| 61 | * @param string $context What the value is for. Valid values are 'view' and 'edit'. |
| 62 | * @return string |
| 63 | */ |
| 64 | public function get_button_text( $context = 'view' ) { |
| 65 | return $this->get_prop( 'button_text', $context ); |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | |-------------------------------------------------------------------------- |
| 70 | | Setters |
| 71 | |-------------------------------------------------------------------------- |
| 72 | | |
| 73 | | Functions for setting product data. These should not update anything in the |
| 74 | | database itself and should only change what is stored in the class |
| 75 | | object. |
| 76 | */ |
| 77 | |
| 78 | /** |
| 79 | * Set product URL. |
| 80 | * |
| 81 | * @since 3.0.0 |
| 82 | * @param string $product_url Product URL. |
| 83 | */ |
| 84 | public function set_product_url( $product_url ) { |
| 85 | $this->set_prop( 'product_url', htmlspecialchars_decode( $product_url ) ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Set button text. |
| 90 | * |
| 91 | * @since 3.0.0 |
| 92 | * @param string $button_text Button text. |
| 93 | */ |
| 94 | public function set_button_text( $button_text ) { |
| 95 | $this->set_prop( 'button_text', $button_text ); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * External products cannot be stock managed. |
| 100 | * |
| 101 | * @since 3.0.0 |
| 102 | * @param bool $manage_stock If manage stock. |
| 103 | */ |
| 104 | public function set_manage_stock( $manage_stock ) { |
| 105 | $this->set_prop( 'manage_stock', false ); |
| 106 | |
| 107 | if ( true === $manage_stock ) { |
| 108 | $this->error( 'product_external_invalid_manage_stock', __( 'External products cannot be stock managed.', 'woocommerce' ) ); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * External products cannot be stock managed. |
| 114 | * |
| 115 | * @since 3.0.0 |
| 116 | * |
| 117 | * @param string $stock_status Stock status. |
| 118 | */ |
| 119 | public function set_stock_status( $stock_status = '' ) { |
| 120 | $this->set_prop( 'stock_status', ProductStockStatus::IN_STOCK ); |
| 121 | |
| 122 | if ( ProductStockStatus::IN_STOCK !== $stock_status ) { |
| 123 | $this->error( 'product_external_invalid_stock_status', __( 'External products cannot be stock managed.', 'woocommerce' ) ); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * External products cannot be backordered. |
| 129 | * |
| 130 | * @since 3.0.0 |
| 131 | * @param string $backorders Options: 'yes', 'no' or 'notify'. |
| 132 | */ |
| 133 | public function set_backorders( $backorders ) { |
| 134 | $this->set_prop( 'backorders', 'no' ); |
| 135 | |
| 136 | if ( 'no' !== $backorders ) { |
| 137 | $this->error( 'product_external_invalid_backorders', __( 'External products cannot be backordered.', 'woocommerce' ) ); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | |-------------------------------------------------------------------------- |
| 143 | | Other Actions |
| 144 | |-------------------------------------------------------------------------- |
| 145 | */ |
| 146 | |
| 147 | /** |
| 148 | * Returns false if the product cannot be bought. |
| 149 | * |
| 150 | * @access public |
| 151 | * @return bool |
| 152 | */ |
| 153 | public function is_purchasable() { |
| 154 | return apply_filters( 'woocommerce_is_purchasable', false, $this ); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Get the add to url used mainly in loops. |
| 159 | * |
| 160 | * @access public |
| 161 | * @return string |
| 162 | */ |
| 163 | public function add_to_cart_url() { |
| 164 | return apply_filters( 'woocommerce_product_add_to_cart_url', $this->get_product_url(), $this ); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Get the add to cart button text for the single page. |
| 169 | * |
| 170 | * @access public |
| 171 | * @return string |
| 172 | */ |
| 173 | public function single_add_to_cart_text() { |
| 174 | return apply_filters( 'woocommerce_product_single_add_to_cart_text', $this->get_button_text() ? $this->get_button_text() : _x( 'Buy product', 'placeholder', 'woocommerce' ), $this ); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Get the add to cart button text. |
| 179 | * |
| 180 | * @access public |
| 181 | * @return string |
| 182 | */ |
| 183 | public function add_to_cart_text() { |
| 184 | return apply_filters( 'woocommerce_product_add_to_cart_text', $this->get_button_text() ? $this->get_button_text() : _x( 'Buy product', 'placeholder', 'woocommerce' ), $this ); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Get the add to cart button text description - used in aria tags. |
| 189 | * |
| 190 | * @since 3.3.0 |
| 191 | * @return string |
| 192 | */ |
| 193 | public function add_to_cart_description() { |
| 194 | /* translators: %s: Product title */ |
| 195 | return apply_filters( 'woocommerce_product_add_to_cart_description', $this->get_button_text() ? $this->get_button_text() : sprintf( __( 'Buy “%s”', 'woocommerce' ), $this->get_name() ), $this ); |
| 196 | } |
| 197 | } |
| 198 |