daily pastebin goal
21%
SHARE
TWEET

auctions Buy now button in the loop

wpgenie Aug 23rd, 2017 (edited) 1,914 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action( 'woocommerce_after_shop_loop_item', 'custom_loop_buy_nowbutton', 11 );
  2.  
  3. function custom_loop_buy_nowbutton( $args = array() ) {
  4.     global $product;
  5.     if ( ! $product->is_purchasable() OR ! $product->is_sold_individually() OR ! $product->is_in_stock() OR $product->is_closed() ) return;
  6.     if ( $product && $product->get_type() == 'auction'  ) {
  7.         $defaults = array(
  8.             'quantity' => 1,
  9.             'class'    => implode( ' ', array_filter( array(
  10.                     'button',
  11.                     'product_type_' . $product->get_type(),
  12.                     $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
  13.                     $product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '',
  14.             ) ) ),
  15.         );
  16.  
  17.         $args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );
  18.  
  19.         $url = $product->is_purchasable() && $product->is_in_stock() ? remove_query_arg( 'added-to-cart', add_query_arg( 'add-to-cart', $product->id ) ) : get_permalink( $product->id );
  20.  
  21.         $url =  apply_filters( 'woocommerce_product_add_to_cart_url', $url, $product );
  22.  
  23.         echo apply_filters( 'woocommerce_loop_add_to_cart_link',
  24.             sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>',
  25.                 esc_url( $url ),
  26.                 esc_attr( 1 ),
  27.                 esc_attr( $product->get_id() ),
  28.                 esc_attr( $product->get_sku() ),
  29.                 esc_attr( isset( $class ) ? $class : 'button' ),
  30.                 sprintf(__( 'Buy now for %s', 'wc_simple_auctions' ),wc_price($product->get_regular_price()) )
  31.             ),
  32.         $product );
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top