Ich versuche, diesen Code zu meinem WooCommerce-Setup hinzuzufügen, das einen Warenkorb-Link hinzufügt, wo immer ich das PHP platziere, und es dann aktualisiert, wenn Artikel im Warenkorb mit AJAX geändert werden: https://docs.woocommerce.com/document/show-cart-contents-total/
Hier sind die Ausschnitte:
HTML-PHP:
<a class="cart-customlocation" href="https://stackoverflow.com/questions/49941502/<?php%20echo%20wc_get_cart_url();%20?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
Im functions.php
Datei:
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<a class="cart-customlocation" href="https://stackoverflow.com/questions/49941502/<?php%20echo%20esc_url(wc_get_cart_url());%20?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
<?php
$fragments['a.cart-customlocation'] = ob_get_clean();
return $fragments;
}
Aber das AJAX funktioniert nicht. Ist das zweite Snippet alles, was ich zur functions.php hinzufügen muss?
Es fühlt sich an, als sollte ich die Funktion aufrufen und nicht nur definieren?
Oder muss ich AJAX generell irgendwie aktivieren, damit es funktioniert?