Product Icon

Buy One Get One Free for WooCommerce

Create BOGO promotions and offer products as gifts to your customers to boost your WooCommerce store's sales.

Custom Rules on Custom Item Data

I have a custom plugin that allows users that spend x amount to choose from a list of specific items. I created this long before your plugin as it was specific to a customer’s requirements. I would love that your plugin would allow a custom rule that says if a product has specific custom data, disqualify from the bogo. Here is my custom addFreeItem function:

function addFreeItem(){
if(isset($_REQUEST[‘freeItem’])) {
global $wpdb;
$itemsLeft = itemsLeft();

if($itemsLeft >= 0){
$unique_cart_item_key = md5( microtime() . rand() );

$cart_item_data = array(‘free_backbar_price’ => 0, ‘unique_key’ => $unique_cart_item_key );
$product_id = $_REQUEST[‘freeItem’];
$variation_id = $_REQUEST[‘variation_id’];
$variation = array($_REQUEST[‘variation_name’] => $_REQUEST[‘variation_value’]);

WC()->cart->add_to_cart( $product_id, 1, $variation_id, $variation, $cart_item_data );
$url = WC()->cart->get_cart_url();
wp_redirect( $url );
exit;
}
}
}

In this example, if an item in the cart had free_backbar_price, that item does not count towards qualification.

I hope that makes sense.

Thanks for your consideration.

Author

Christopher Hampton

Current Status

Open

Last updated: December 21, 2024

0 comments

Log in to comment on this feature request.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.