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.
Open
Last updated: December 21, 2024
0 comments
Log in to comment on this feature request.