Advertisement
Udoro

Build Woocommerce store in Oxygen part 2 - PHP code blocks

Jul 25th, 2021
1,097
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. //-------------QUANTITY IN CART (activate relevant snippet for this to work) -------------------
  2.  
  3. <?php
  4.  
  5. global $product;
  6.  
  7.  
  8. $product_id = $product->get_id();
  9. $in_cart = false;
  10.  
  11. foreach( WC()->cart->get_cart() as $cart_item ) {
  12. $product_in_cart = $cart_item['product_id'];
  13. if ( $product_in_cart === $product_id ) $in_cart = true;
  14. }
  15.  
  16. if ( $in_cart ) {
  17.  
  18. echo do_shortcode('[product_qty id="'. $product_id . '"]');
  19.  
  20. }
  21.  
  22. ?>
  23.  
  24.  
  25. //------------------BUY NOW BUTTON---------------------
  26.  
  27. <a href="<?php echo esc_url(home_url( '/' ));?>checkout/?add-to-cart=<?php the_ID();?>" class="quick-buy single_add_to_cart_button button alt" ><?php esc_html_e('Buy now', 'demo.local'); ?></a>
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement