Skip to content

Commit

Permalink
Add support for the Bricks theme builder
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Sep 28, 2024
1 parent c6e5733 commit 4cbbfa3
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion assets/integration/woocommerce.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Release date: 2024-MM-DD
Find out about what's new in our [our release post](https://gtmkit.com/gtm-kit-2-1/).

#### Enhancements:
* Added support for the Bricks theme builder.

#### Bugfixes:
* In some cases other plugins or a theme could block GTM Kit from firing JS event like the one the fires the add_to_cart GTM event.
Expand Down
23 changes: 23 additions & 0 deletions src/Common/Conditionals/BricksConditional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* GTM Kit plugin file.
*
* @package GTM Kit
*/

namespace TLA_Media\GTM_Kit\Common\Conditionals;

/**
* Conditional that is only met when the Bricks theme is active.
*/
class BricksConditional implements Conditional {

/**
* Returns `true` when the Bricks theme is installed and activated.
*
* @return bool `true` when the Bricks theme is installed and activated.
*/
public function is_met(): bool {
return ( \wp_get_theme()->get( 'Name' ) === 'Bricks' || wp_get_theme()->get( 'Template' ) === 'bricks' );
}
}
22 changes: 20 additions & 2 deletions src/Integration/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Automattic\WooCommerce\StoreApi\Schemas\V1\CartItemSchema;
use Automattic\WooCommerce\StoreApi\Schemas\V1\ProductSchema;
use Exception;
use TLA_Media\GTM_Kit\Common\Conditionals\BricksConditional;
use TLA_Media\GTM_Kit\Common\RestAPIServer;
use TLA_Media\GTM_Kit\Common\Util;
use TLA_Media\GTM_Kit\Options;
Expand Down Expand Up @@ -244,6 +245,7 @@ public function get_global_settings( array $global_settings ): array {
$global_settings['wc']['view_item']['config'] = (int) $this->options->get( 'integrations', 'woocommerce_variable_product_tracking' );
$global_settings['wc']['view_item_list']['config'] = (int) $this->options->get( 'integrations', 'woocommerce_view_item_list_limit' );
$global_settings['wc']['wishlist'] = false;
$global_settings['wc']['css_selectors'] = $this->get_css_selectors();
$global_settings['wc']['text'] = [
'wp-block-handpicked-products' => __( 'Handpicked Products', 'gtm-kit' ),
'wp-block-product-best-sellers' => __( 'Best Sellers', 'gtm-kit' ),
Expand All @@ -256,15 +258,31 @@ public function get_global_settings( array $global_settings ): array {
'shipping-tier-not-found' => __( 'Shipping tier not found', 'gtm-kit' ),
'payment-method-not-found' => __( 'Payment method not found', 'gtm-kit' ),
];
$global_settings['wc']['css_selectors'] = [

return $global_settings;
}

/**
* Get CSS Selectors
*
* @return array{product_list_select_item: string, product_list_element: string, product_list_exclude: string, product_list_add_to_cart: string}
*/
private function get_css_selectors(): array {

$css_selectors = [
'product_list_select_item' => '.products .product:not(.product-category) a:not(.add_to_cart_button.ajax_add_to_cart,.add_to_wishlist),' .
'.wc-block-grid__products li:not(.product-category) a:not(.add_to_cart_button.ajax_add_to_cart,.add_to_wishlist),' .
'.woocommerce-grouped-product-list-item__label a:not(.add_to_wishlist)',
'product_list_element' => '.product,.wc-block-grid__product',
'product_list_exclude' => '',
'product_list_add_to_cart' => '.add_to_cart_button.ajax_add_to_cart:not(.single_add_to_cart_button)',
];

return $global_settings;
if ( ( new BricksConditional() )->is_met() ) {
$css_selectors['product_list_add_to_cart'] .= ',.add_to_cart_button.brx_ajax_add_to_cart:not(.single_add_to_cart_button)';
}

return $css_selectors;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/js/woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function gtmkitLoad() {

if (
eventTargetElement.closest(
'.add_to_cart_button.ajax_add_to_cart:not(.single_add_to_cart_button)'
window.gtmkit_settings.wc.css_selectors.product_list_add_to_cart
)
) {
event = 'add_to_cart';
Expand Down
1 change: 1 addition & 0 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'TLA_Media\\GTM_Kit\\Admin\\SetupWizard' => $baseDir . '/src/Admin/SetupWizard.php',
'TLA_Media\\GTM_Kit\\Admin\\TemplatesOptionsPage' => $baseDir . '/src/Admin/TemplatesOptionsPage.php',
'TLA_Media\\GTM_Kit\\Admin\\UpgradesOptionsPage' => $baseDir . '/src/Admin/UpgradesOptionsPage.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\BricksConditional' => $baseDir . '/src/Common/Conditionals/BricksConditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\Conditional' => $baseDir . '/src/Common/Conditionals/Conditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\ContactForm7Conditional' => $baseDir . '/src/Common/Conditionals/ContactForm7Conditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\EasyDigitalDownloadsConditional' => $baseDir . '/src/Common/Conditionals/EasyDigitalDownloadsConditional.php',
Expand Down
1 change: 1 addition & 0 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ComposerStaticInit12fa396dcd6fc263a33fd78c6d8551b8
'TLA_Media\\GTM_Kit\\Admin\\SetupWizard' => __DIR__ . '/../..' . '/src/Admin/SetupWizard.php',
'TLA_Media\\GTM_Kit\\Admin\\TemplatesOptionsPage' => __DIR__ . '/../..' . '/src/Admin/TemplatesOptionsPage.php',
'TLA_Media\\GTM_Kit\\Admin\\UpgradesOptionsPage' => __DIR__ . '/../..' . '/src/Admin/UpgradesOptionsPage.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\BricksConditional' => __DIR__ . '/../..' . '/src/Common/Conditionals/BricksConditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\Conditional' => __DIR__ . '/../..' . '/src/Common/Conditionals/Conditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\ContactForm7Conditional' => __DIR__ . '/../..' . '/src/Common/Conditionals/ContactForm7Conditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\EasyDigitalDownloadsConditional' => __DIR__ . '/../..' . '/src/Common/Conditionals/EasyDigitalDownloadsConditional.php',
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'tlamedia/gtm-kit',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => 'b3228238bcfd8a33cbd843ee052f21ca9b557927',
'reference' => 'c6e57338f099840ebaf09e6c6adb8df7c2fa34fe',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'tlamedia/gtm-kit' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => 'b3228238bcfd8a33cbd843ee052f21ca9b557927',
'reference' => 'c6e57338f099840ebaf09e6c6adb8df7c2fa34fe',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down

0 comments on commit 4cbbfa3

Please sign in to comment.