Advertisement
wpgenie

auctions Buy now button in the loop

Aug 23rd, 2017 (edited)
3,672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. /* visit us - https://wpgenie.org */
  2.  
  3. add_action( 'woocommerce_after_shop_loop_item', 'custom_loop_buy_nowbutton', 11 );
  4.  
  5. function custom_loop_buy_nowbutton( $args = array() ) {
  6.     global $product;
  7.     if ( ! $product->is_purchasable() OR ! $product->is_sold_individually() OR ! $product->is_in_stock() OR $product->is_closed() ) return;
  8.     if ( $product && $product->get_type() == 'auction'  ) {
  9.         $defaults = array(
  10.             'quantity' => 1,
  11.             'class'    => implode( ' ', array_filter( array(
  12.                     'button',
  13.                     'product_type_' . $product->get_type(),
  14.                     $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
  15.                     $product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '',
  16.             ) ) ),
  17.         );
  18.  
  19.         $args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );
  20.  
  21.         $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 );
  22.  
  23.         $url =  apply_filters( 'woocommerce_product_add_to_cart_url', $url, $product );
  24.  
  25.         echo apply_filters( 'woocommerce_loop_add_to_cart_link',
  26.             sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>',
  27.                 esc_url( $url ),
  28.                 esc_attr( 1 ),
  29.                 esc_attr( $product->get_id() ),
  30.                 esc_attr( $product->get_sku() ),
  31.                 esc_attr( isset( $class ) ? $class : 'button' ),
  32.                 sprintf(__( 'Buy now for %s', 'wc_simple_auctions' ),wc_price($product->get_regular_price()) )
  33.             ),
  34.         $product );
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement