is_bookable( $product ) ) { return $text; } return __( 'Select dates', 'abogo-booking' ); } /** * Point the button at the product page, the only place holding a calendar. * * @since 1.0.0 * @param string $url Address the button points to. * @param \WC_Product $product Product being listed. * @return string */ public function button_url( $url, $product = null ) { if ( ! $this->is_bookable( $product ) ) { return $url; } return $product->get_permalink(); } /** * Stop the listing from adding the product without its dates. * * @since 1.0.0 * @param array $args Arguments of the button. * @param \WC_Product $product Product being listed. * @return array */ public function button_args( $args, $product = null ) { if ( ! $this->is_bookable( $product ) ) { return $args; } if ( isset( $args['class'] ) ) { $args['class'] = trim( str_replace( array( 'ajax_add_to_cart', 'add_to_cart_button' ), '', $args['class'] ) ); } unset( $args['attributes']['data-product_id'], $args['attributes']['data-quantity'] ); return $args; } /** * Whether the product shown is sold by date. * * @since 1.0.0 * @param \WC_Product|null $product Product being listed. * @return bool */ private function is_bookable( $product ) { return $product instanceof \WC_Product && Settings::is_bookable( $product->get_id() ); } }