Skip to content

Instantly share code, notes, and snippets.

@xadapter
Created December 18, 2019 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/a19efbd312ccbc4b6b522e4b1a52927d to your computer and use it in GitHub Desktop.
Save xadapter/a19efbd312ccbc4b6b522e4b1a52927d to your computer and use it in GitHub Desktop.
woo-credits compatibility - following functions to be modified in woo-credits plugin
//added phive_booking condition also, so that credits can be calculated according to the number of recurrences and the number of persons if "Consider each participant as separate booking" is checked.
public static function get_credit_from_cart_item($item, $single = true, $composite = false)
{
$total_credits_amount = 0;
$prod_id = wdcp_get_product_id_cart_item($item);
$prod_id = wdcp_icl_object_id($prod_id);
$product = $item['data'];
if (!$product->is_type('credits'))
{
$credits_amount = get_post_meta($prod_id, '_credits_amount', true);
if ($product->is_type('booking') && $product->get_duration_type() == 'customer') {
$duration = $item['booking']['_duration'];
$credits_amount = $credits_amount * $duration;
}
if (function_exists('wceb_is_bookable') && wceb_is_bookable($product) && isset($item['_booking_duration'])) {
$booking_duration = $item['_booking_duration'];
$credits_amount = $credits_amount * $booking_duration;
}
if ($product->is_type('booking')) {
$credits_amount = wdcp_wcb_cart_calculate_credits($product, $item);
}
//added phive_booking also, so that credits can be calculated according to the number of recurrences and the number of persons if "Consider each participant as separate booking" is checked.
if ($product->is_type('phive_booking'))
{
if (isset($item['ph_recurrent_booking_recurrence']) && !empty($item['ph_recurrent_booking_recurrence']))
{
if(is_numeric($credits_amount))
{
$credits_amount = $credits_amount * ($item['ph_recurrent_booking_recurrence'] + 1)
;
}
}
if(isset($item['phive_booked_persons']) && !empty($item['phive_booked_persons']))
{
$persons_as_booking = get_post_meta( $prod_id, "_phive_booking_persons_as_booking", 1 );
if($persons_as_booking == 'yes')
{
$no_of_persons = maybe_unserialize($item['phive_booked_persons']);
if(is_array($no_of_persons))
{
$number_of_persons = !empty($no_of_persons[0]) ? $no_of_persons[0] : 1;
if(is_numeric($credits_amount))
{
$credits_amount = $credits_amount * $number_of_persons;
}
}
}
}
}
//phive_booking end
if ($credits_amount || (is_numeric($credits_amount) && $credits_amount == 0)) {
if (!$single) {
$credits_amount = $item['quantity'] * $credits_amount;
}
$total_credits_amount += $credits_amount;
}
if ($composite && $item['data']->is_type('composite')) {
$composite_data = $item['composite_data'];
$composite_credits = self::get_composite_credits($composite_data);
if ($composite_credits) {
$total_credits_amount += $composite_credits;
}
}
}
return $total_credits_amount;
}
//added phive_booking in $ptypes array to display credit options on product edit page.
public static function get_product_types2()
{
$ptypes = array(
'simple',
'appointment',
'booking',
'course',
'bundle',
'composite',
'promotion_package',
'phive_booking', //added phive_booking to display credit options on product edit.
);
return $ptypes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment