WooCommerce theme customizations


/ Published in: PHP
Save to your folder(s)

Various WooCommerce theme customizations. See comments in code.


Copy this code and paste it in your HTML
  1. // Ensure cart contents update when products are added to the cart via AJAX, in "$0.00" format
  2. add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
  3.  
  4. function woocommerce_header_add_to_cart_fragment( $fragments ) {
  5. ob_start();
  6. ?>
  7. <a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf (_n( '%d item', '%d items', WC()->cart->cart_contents_count ), WC()->cart->cart_contents_count ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
  8. <?php
  9.  
  10. $fragments['a.cart-contents'] = ob_get_clean();
  11.  
  12. return $fragments;
  13. }
  14.  
  15. // ADD BRAND CUSTOM FIELD TO SINGLE PRODUCT SUMMARY
  16. add_action( 'woocommerce_single_product_summary', 'add_custom_field', 7 );
  17. add_action( 'woocommerce_after_shop_loop_item_title', 'add_custom_field', 40 );
  18. function add_custom_field() {
  19. global $post;
  20.  
  21. echo "<div class='artist'>";
  22. echo get_post_meta( $post->ID, 'Collaborative Artist', true );
  23. echo "</div>";
  24.  
  25. return true;
  26. }
  27.  
  28. // Change root breadcrumb link
  29. add_filter( 'woocommerce_breadcrumb_defaults', 'jk_change_breadcrumb_home_text' );
  30. function jk_change_breadcrumb_home_text( $defaults ) {
  31. // Change the breadcrumb home text from 'Home' to 'Shop'
  32. $defaults['home'] = 'Shop';
  33. return $defaults;
  34. }
  35. add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
  36. function woo_custom_breadrumb_home_url() {
  37. return '/shop';
  38. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.