Fixes missing cart image by adjusting script enqueue and adding MutationObserver to handle dynamically rendered book wrappers

This commit is contained in:
2026-01-20 02:52:52 +00:00
parent d4978a7122
commit 6fe38f323c
2 changed files with 60 additions and 24 deletions
+19 -6
View File
@@ -26,18 +26,31 @@ add_action('template_redirect', function() {
});
function enqueue_shop_links_script() {
if (is_singular()) {
wp_enqueue_script('search_shop_link',plugins_url('/js/search_shop_link.js', __FILE__));
wp_add_inline_script( 'search_shop_link', 'window.searchShopLinkImageUrl = "' . plugins_url('assets/cart_add.png', __FILE__) . '";' );
if (is_singular()) {
// 1. Enqueue your JS file
wp_enqueue_script(
'search_shop_link',
plugins_url('js/search_shop_link.js', __FILE__),
[],
false,
true
);
// 2. Localize data for that script
wp_localize_script(
'search_shop_link',
'SearchShopLinkData',
[
'imageUrl' => plugins_url('assets/cart_add.png', __FILE__)
]
);
}
}
add_action('wp_enqueue_scripts', 'enqueue_shop_links_script');
function br_replace_book_wrapper($html) {
if (strpos($html, 'product-details') === false) {
return $html;