WooCommerce迷你购物车事件触发器

时间:2018-09-17 13:13:10

标签: php jquery wordpress woocommerce

每次通过ajax将产品添加到购物篮并且刷新迷你购物车时,我都需要能够运行一些jQuery。我不能只是简单地为添加到购物车创建一个偶数,因为,我运行一些jQuery来检查迷你购物车中是否包含产品,但是添加到购物车甚至在迷你购物车添加产品之前运行。这意味着我的if语句变为假。

除了在jQuery中创建超时外,我还能做什么?

这是我根据当前答案修改的代码;

add_action( 'wp_footer', 'ajax_add_tocart_event' );

function ajax_add_tocart_event() {
    ?>
     <script type="text/javascript">
       jQuery( 'body' ).on( 'added_to_cart', function() {
            if( $('#mini_wrap .cart_list').length ){
                alert('hi');
            }
       } );
    </script>
    <?php
}

2 个答案:

答案 0 :(得分:2)

您可以使用以下代码。

(node:5858) UnhandledPromiseRejectionWarning: 
Error: net::ERR_TUNNEL_CONNECTION_FAILED at https://www.apple.com/
at navigate (/xxx/node_modules/_puppeteer@1.8.0@puppeteer/lib/Page.js:622:37)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:5858) UnhandledPromiseRejectionWarning:
Unhandled promise rejection. This error originated either by throwing
inside of an async function without a catch block, 
or by rejecting a promise which was not handled with .catch(). 
(rejection id: 1)

答案 1 :(得分:1)

将此代码放入private adalConfig = { tenant: 'ac6e97c2-a8b0-4555-97b3-70001a6a7448', clientId: '15d2adcd-6435-4ba7-9b95-d00508d00b76', redirectUri: "http://localhost:4200/auth-callback/", logOutUri: "http://localhost:4200/logout", postLogoutRedirectUri: "http://localhost:4200/logout", endpoints: { "https://localhost:63126": "454e12a6-f6ee-4e63-bc62-6de13da2789b" } 文件中。

functions.php