Code Snippets

Redirect to the Cart page when winner clicks Pay Now

Redirect to the Cart page instead of going directly to Checkout when winning bidder clicks Pay Now, this code snippet requires Auctions for WooCommerce v2.5 or higher: add_filter( 'auctions_for_woocommerce_pay_now_button' , 'custom_auctions_for_woocommerce_pay_now_button', 10); function custom_auctions_for_woocommerce_pay_now_button( $data ){ global $product; if ( ! $product ) { return $data; } return esc_url( add_query_arg( 'pay-auction', $product->get_auction_id(), wc_get_cart_url() ) ); } add_filter( 'auctions_for_woocommerce_pay_auction_redirect' , 'custom_auctions_for_woocommerce_pay_auction_redirect', 10); function custom_auctions_for_woocommerce_pay_auction_redirect( $data ){ return esc_url( remove_query_arg( array( 'pay-auction', 'quantity', 'product_id' ), wc_get_cart_url() ) ...
Read More
/ Code Snippets

Add user’s won auctions to cart

This is code snippet that adds user's won auctions to cart automatically: add_action( 'template_redirect', 'afw_add_won_auctions_to_cart', 10 ); function afw_add_won_auctions_to_cart() { if ( ! is_admin() && is_user_logged_in() ) { $user_id = get_current_user_id(); $auction_visibility_terms = wc_get_auction_visibility_term_ids(); $product_visibility_in = array( $auction_visibility_terms['sold'] ); $args = array( 'post_type' => 'product', 'posts_per_page' => '-1', 'meta_query' => array( array( 'key' => '_auction_current_bider', 'value' => $user_id, ), array( 'key' => '_auction_payed', 'compare' => 'NOT EXISTS', ), ), 'tax_query' => array( 'taxonomy' => 'auction_visibility', ...
Read More
/ Code Snippets

Display “no results” message when there are no results in shortcode

To add message if there are no results in shortcode please use code snippet below: function afw_action_woocommerce_shortcode_products_loop_no_results( $attributes ) { echo __( 'No auction(s) found.', 'my-custom-language-domain' ); } add_action( 'woocommerce_shortcode_ending_soon_auctions_loop_no_results', 'afw_action_woocommerce_shortcode_products_loop_no_results', 10, 1 ); add_action( 'woocommerce_shortcode_all_user_auctions_loop_no_results', 'afw_action_woocommerce_shortcode_products_loop_no_results', 10, 1 ); For ending_soon_auctions shortcode hook is woocommerce_shortcode_ending_soon_auctions_loop_no_results, in general hook is woocommerce_shortcode_[shortcode_name]_loop_no_results. This is applicable for both Auctions for Woo and Competitions for Woo plugins ...
Read More
/ Code Snippets

Pay Now adds won auction to cart instead going to checkout

Here is modified template where Pay Now button adds won auction to cart rather than going to classic checkout. Template should be placed in your child theme, wp-content\themes\child-theme-name\woocommerce\single-product\pay.php <?php /** * Auction pay * */ ​ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } ​ global $product, $post; ​ if ( ! ( $product && $product->is_type( 'auction' ) ) ) { return; } ​ $user_id = get_current_user_id(); ​ ...
Read More
/ Code Snippets

How to increase bid step for bid increment value to be more than 1

In documentation's FAQ item no 3 explains how can you accomplish behaviour where bid increment is going up in steps different than $1 - https://wpinstitut.com/auctions-for-woocommerce-documentation/ Basically you need to copy bid.php template to your child theme\woocommerce\single-product\auction-bid-form.php and make following change step="any" becomes step="<?php echo ($product->get_auction_bid_increment()) ? $product->get_auction_bid_increment() : '1' ?>" This will make steps to increment by value set in min bid increment in auction details in wp-admin for example if you set min bid ...
Read More
/ Code Snippets

Add fee on checkout for auction winner

To add fee on checkout for auction winner you can use code snippet below in your functions.php file. To change percentage of fee just modify global_fee or fee_per_auction variable. add_action( 'woocommerce_cart_calculate_fees', 'afw_add_fee_on_checkout' ); function afw_add_fee_on_checkout( $cart_object ) { $global_fee = 0.00; // initialize special global fee, value 25.45 means fee of $25.45 $fee_per_auction = 0.30; // fee per product, 0.25 => 25% foreach ( $cart_object->cart_contents as $key => $value ) { $product_id_cart = $value['product_id']; //get ...
Read More
/ Code Snippets

Custom page template with custom query

In this post we published quick example of custom query for AfW implemented as page template. You can download example of custom page template called "Auctions Example Template" here. Screenshot explains how to set it in WordPress editor. Code in example is basic one (but working) you will probably need to customize the code match your requirements ...
Read More
/ Code Snippets

Custom min bid increase based on current bid value

Is there a possibility to have minimal bid increments based on current bid amount? Yes, and you can use this code snippet in your child theme functions.php or via Code Snippets plugin. function afw_bid_value_classes( $metadata, $object_id, $meta_key, $single ) { if ( isset( $meta_key ) && '_auction_bid_increment' === $meta_key ) { $product = wc_get_product( $object_id ); if( (! $product) || $product->get_type() != 'auction' ){ return $metadata; } $bid_value = $product->get_curent_bid(); switch ( $bid_value ) { ...
Read More
/ Code Snippets

How can I prevent subscriber role from bidding?

To accomplish that you can use code snippet below: // snippet that prevents bidding based on user role add_filter( 'auctions_for_woocommerce_before_place_bid_filter' , 'afw_prevent_bid_by_user_role' ); function afw_prevent_bid_by_user_role() { $current_user = wp_get_current_user(); if ( in_array ( 'subscriber', $current_user->roles ) ){ wc_add_notice( esc_html__('Your user role cannot bid.', 'auctions-for-woocommerce'), 'error' ); return FALSE; } else { // user can place a bid return TRUE; } } ...
Read More
/ Code Snippets

Automatically create a WC order when the auction ends (with Auctions for WooCommerce)

Alex created code that programmatically creates a WooCommerce order when an auction (with bids) ends (thanks Alex!). You can use it as code snippet in your functions.php or as standalone plugin. Download it here https://github.com/f2pnt8/WooCommerce-Create-Order-on-Auction-End ...
Read More
/ Code Snippets