Fixes missing cart image by adjusting script enqueue and adding MutationObserver to handle dynamically rendered book wrappers
This commit is contained in:
+19
-6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user