PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / compatibility / class-merchant-botiga-theme.php

class-merchant-botiga-theme.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.3.2, at inc/compatibility/class-merchant-botiga-theme.php

133 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 /**
7 * Botiga theme compatibility layer
8 */
9 if ( ! class_exists( 'Merchant_Botiga_Theme' ) ) {
10 class Merchant_Botiga_Theme {
11
12 /**
13 * Constructor.
14 */
15 public function __construct() {
16 add_action( 'wp_enqueue_scripts', array( $this, 'styles' ) );
17
18 add_filter( 'merchant_admin_module_field_wrapper_classes', array( $this, 'size_chart_placement_field_classes' ), 10, 4 );
19 add_filter( 'merchant_admin_module_field_description', array( $this, 'size_chart_placement_field_description' ), 10, 4 );
20 }
21
22 /**
23 * Load compatibility styles if the Botiga theme is installed and active.
24 *
25 * @return void
26 */
27 public function styles() {
28 if ( ! merchant_is_botiga_active() ) {
29 return;
30 }
31
32 wp_enqueue_style(
33 'merchant-botiga-compatibility',
34 MERCHANT_URI . 'assets/css/compatibility/botiga/style.min.css',
35 array(),
36 MERCHANT_VERSION
37 );
38 }
39
40 /**
41 * Grey out the Size Chart display position field while Botiga owns the placement.
42 *
43 * @param array<int, string> $classes Field wrapper classes.
44 * @param array<string, mixed> $settings Field configuration.
45 * @param mixed $value Current field value.
46 * @param string $module_id Module ID.
47 *
48 * @return array<int, string>
49 */
50 public function size_chart_placement_field_classes( $classes, $settings, $value, $module_id ) {
51 if ( ! $this->is_size_chart_placement_field( $settings, $module_id ) || ! $this->botiga_owns_placement() ) {
52 return $classes;
53 }
54
55 $classes[] = 'botiga-merchant-module-field-disabled';
56
57 return $classes;
58 }
59
60 /**
61 * Tell the merchant where the placement is actually coming from.
62 *
63 * @param string $desc Field description.
64 * @param array<string, mixed> $settings Field configuration.
65 * @param mixed $value Current field value.
66 * @param string $module_id Module ID.
67 *
68 * @return string
69 */
70 public function size_chart_placement_field_description( $desc, $settings, $value, $module_id ) {
71 if ( ! $this->is_size_chart_placement_field( $settings, $module_id ) || ! $this->botiga_owns_placement() ) {
72 return $desc;
73 }
74
75 // The renderer runs the description through wp_kses_post(), so the link and
76 // the angle brackets in the breadcrumb survive without being escaped here.
77 return sprintf(
78 /* Translators: 1. Link open tag 2. Link close tag */
79 __( 'The display is being controlled by Botiga under %1$sCustomizer > WooCommerce > Single Product > Layout (Elements)%2$s', 'merchant' ),
80 '<a href="' . esc_url( admin_url( 'customize.php?autofocus[section]=botiga_section_single_product_layout' ) ) . '" target="_blank">',
81 '</a>'
82 );
83 }
84
85 /**
86 * Whether the given field is the Size Chart display position picker.
87 *
88 * @param array<string, mixed> $settings Field configuration.
89 * @param string $module_id Module ID.
90 *
91 * @return bool
92 */
93 private function is_size_chart_placement_field( $settings, $module_id ) {
94 return 'size-chart' === $module_id && isset( $settings['id'] ) && 'display_hook' === $settings['id'];
95 }
96
97 /**
98 * Whether Botiga's single product elements decide where the size chart renders.
99 *
100 * Botiga greys out the placement fields of the modules it takes over, but its
101 * map does not know about the size chart picker yet. Stand in until it does.
102 *
103 * @return bool
104 */
105 private function botiga_owns_placement() {
106 if ( ! merchant_is_botiga_active() || ! class_exists( 'Botiga_Merchant_Single_Product_Elements' ) ) {
107 return false;
108 }
109
110 // The Merchant integration is the only thing hooking this action, and it does
111 // so after its own opt-out checks, so it doubles as an "integration is live" flag.
112 if ( ! has_action( 'botiga_before_render_single_product_elements' ) ) {
113 return false;
114 }
115
116 // On the full width gallery the theme leaves the placement to the module.
117 if ( 'gallery-full-width' === get_theme_mod( 'single_product_gallery', 'gallery-default' ) ) {
118 return false;
119 }
120
121 $theme_fields = Botiga_Merchant_Single_Product_Elements::get_module_admin_field_descriptions();
122
123 return ! isset( $theme_fields['size-chart']['display_hook'] );
124 }
125 }
126
127 /**
128 * The class object can be accessed with "global $botiga_compatibility", to allow removing actions.
129 * Improving Third-party integrations.
130 */
131 $merchant_botiga_compatibility = new Merchant_Botiga_Theme();
132 }
133