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, 0.25 = 25% $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 the product id ...
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

How can I place “Add to Watchlist” link to product archive page for all auctions?

You can add this code (thx Mike) to your child theme functions.php file: // display "add to watchlist" on all product archive pages add_action( 'woocommerce_shop_loop_item_title', 'add_to_watchlist', 50 ); function add_to_watchlist() { global $product; if (isset($product) && $product == true) { wc_get_template('single-product/watchlist-link.php'); } } ...
Read More
/ Code Snippets