PluginProbe
WooCommerce / 11.1.0-rc.2
WooCommerce v11.1.0-rc.2
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / src / Internal / ProductImage / MatchImageBySKU.php
MatchImageBySKU.php
79 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MatchImageBySKU class file.
4 */
5
6 namespace Automattic\WooCommerce\Internal\ProductImage;
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Class for the product image matching by SKU.
12 */
13 class MatchImageBySKU {
14
15 /**
16 * The name of the setting for this feature.
17 *
18 * @var string
19 */
20 private $setting_name = 'woocommerce_product_match_featured_image_by_sku';
21
22 /**
23 * MatchImageBySKU constructor.
24 */
25 public function __construct() {
26 $this->init_hooks();
27 }
28
29 /**
30 * Initialize the hooks used by the class.
31 */
32 private function init_hooks() {
33 add_filter( 'woocommerce_get_settings_products', array( $this, 'add_product_image_sku_setting' ), 110, 2 );
34 }
35
36 /**
37 * Is this feature enabled.
38 *
39 * @since 8.3.0
40 * @return bool
41 */
42 public function is_enabled() {
43 return wc_string_to_bool( get_option( $this->setting_name ) );
44 }
45
46 /**
47 * Handler for 'woocommerce_get_settings_products', adds the settings related to the product image SKU matching table.
48 *
49 * @param array $settings Original settings configuration array.
50 * @param string $section_id Settings section identifier.
51 * @return array New settings configuration array.
52 *
53 * @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
54 */
55 public function add_product_image_sku_setting( array $settings, string $section_id ): array {
56 if ( 'advanced' !== $section_id ) {
57 return $settings;
58 }
59
60 $settings[] = array(
61 'title' => __( 'Product image matching by SKU', 'woocommerce' ),
62 'type' => 'title',
63 );
64
65 $settings[] = array(
66 'title' => __( 'Match images', 'woocommerce' ),
67 'desc' => __( 'Set product featured image when uploaded image file name matches product SKU.', 'woocommerce' ),
68 'id' => $this->setting_name,
69 'default' => 'no',
70 'type' => 'checkbox',
71 'checkboxgroup' => 'start',
72 );
73
74 $settings[] = array( 'type' => 'sectionend' );
75
76 return $settings;
77 }
78 }
79