/*
Theme Name: Phlox Pro Child
Theme URI: http://phlox.pro/go/
Template: phlox-pro
Author: averta
Author URI: http://www.averta.net
Description: Phlox is a modern, lightweight and customizable theme perfect for almost any type of website including, blog, portfolio, agency, startup, new &amp; magazine, restaurant, travel, and photography as well as WooCommerce storefront. What makes the Phlox unbeatable is being fast, truly responsive, translation ready, RTL layout, built with SEO in mind, professional portfolio features, professional news and magazine features, 45 exclusive widgets and elements, WooCommerce Ready, WPML ready, 100% GDPR compliance, reliable with regular updates, and also integrated with Elementor and Visual Composer page builders.
Tags: one-column,two-columns,three-columns,four-columns,left-sidebar,right-sidebar,grid-layout,custom-menu,custom-colors,editor-style,featured-images,featured-image-header,footer-widgets,full-width-template,post-formats,sticky-post,theme-options,translation-ready,blog,e-commerce,portfolio,threaded-comments,custom-logo
Version: 5.17.7.1764242941
Updated: 2025-11-27 03:29:01

*/

add_action( 'woocommerce_payment_complete', 'wpdesk_set_completed_for_paid_orders' );

function wpdesk_set_completed_for_paid_orders( $order_id ) {

    $complex_type_exists = false;
    $order = wc_get_order( $order_id );

    $order_items = $order->get_items();
    
    foreach( $order_items as $item_id => $item ){
    
    	// methods of WC_Order_Item class
    
    	// The element ID can be obtained from an array key or from:
    	$item_id = $item->get_id();
    
    	// methods of WC_Order_Item_Product class
    
    	$item_name = $item->get_name(); // Name of the product
    	$item_type = $item->get_type(); // Type of the order item ("line_item")
    
    	$product_id = $item->get_product_id(); // the Product id
    	$wc_product = $item->get_product();    // the WC_Product object
    	
    	if($wc_product->get_type() != ProductType::SIMPLE)
    	{
            $complex_type_exists = true;
    	}
    }
    
    if($complex_type_exists === false) 
    {
        $order->update_status( 'completed' );
    }
    
}

/**
 * Will put bookings into a Paid status if the order is "completed".
 * 
 * @param int $order_id The order id
 */
function auto_change_booking_status_to_paid( $order_id ) {
	
	// Get the order, then make sure its payment method is COD.
	$order = wc_get_order( $order_id );
	if ( 'completed' == $order->get_status() ) {

    	// Call the data store class so we can get bookings from the order.
    	$booking_data = new WC_Booking_Data_Store();
    	$booking_ids  = $booking_data->get_booking_ids_from_order_id( $order_id );
    	// If we have bookings go through each and update the status.
    	if ( is_array( $booking_ids ) && count( $booking_ids ) > 0 ) {
    		foreach ( $booking_ids as $booking_id ) {
    			$booking = get_wc_booking( $booking_id );
    			    // Update status
                if( $booking->get_status() != 'paid' )
                    $booking->update_status( 'paid', 'order_note' );
    		}
    	}
	}
}
add_action( 'woocommerce_order_status_processing', 'auto_change_booking_status_to_paid', 20 );

add_action( 'init', 'blockusers_init' );
function blockusers_init() {
    if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
        wp_redirect( home_url() );
        exit;
    }
}

/**
 * Will make the Bookings calendar default to the month with the first available booking.
 */
add_filter( 'wc_bookings_calendar_default_to_current_date', '__return_false' );