public/wordpress/wp-content/plugins/wp-courseware/includes/functions/cart.php
/**
 * Add to Cart Link.
 *
 * @since 4.3.0
 *
 * @param \WPCW\Models\Course The course object.
 * @param array $args The array of arguments to pass to the button
 * @param bool  $display_message To display the already enrolled message.
 * @param bool  $force Force the display of the button if they are logged in or not.
 *
 * @return string The cart link html.
 */
Add to Cart Link.

@param \WPCW\Models\Course The course object.
@param array $args The array of arguments to pass to the button
@param bool  $display_message To display the already enrolled message.
@param bool  $force Force the display of the button if they are logged in or not.

@return string The cart link html.
Add to Cart Link . @param \ WPCW \ Models \ Course The course object . @param array $args The array of arguments to pass to the button @param bool $display_message To display the already enrolled message . @param bool $force Force the display of the button if they are logged in or not . @return string The cart link html .
function wpcw_add_to_cart_link( $course, $args = array(), $display_message = true, $force = false ) {
	if ( ! $course instanceof \WPCW\Models\Course ) {
		return;
	}
	if ( ! $force && is_user_logged_in() && $course->can_user_access( get_current_user_id() ) ) {
		if ( $display_message ) {
			return apply_filters( 'wpcw_course_already_enrolled_text', sprintf( __( '<p>You have already been enrolled into <strong>%s</strong>.</p>', 'wp-courseware' ), $course->get_course_title() ) );
		} else {
			return;
		}
	}
	if ( ! $force && wpcw_is_course_in_cart( $course->get_course_id() ) ) {
		return wpcw_get_checkout_link();
	}
	$defaults = array(
		'text'         => esc_html__( 'Purchase', 'wp-courseware' ),
		'quantity'     => 1,
		'class'        => implode( ' ', array_filter( array(
			'wpcw-button wpcw-button-primary',
			'wpcw-add-to-cart',
			apply_filters( 'wpcw_cart_ajax_enabled', true ) ? 'wpcw-ajax-add-to-cart' : '',
		) ) ),
		'attributes'   => array(
			'data-course_id' => $course->get_course_id(),
			'rel'            => 'nofollow',
		),
		'installments' => false,
	);
	$args = apply_filters( 'wpcw_add_to_cart_args', wp_parse_args( $args, $defaults ), $course->get_course_id() );
	if ( $args['installments'] ) {
		$args['attributes']['data-installments'] = true;
		$args['class'] .= ' wpcw-add-to-cart-installments';
		$text = ( 'Installments' === $args['text'] )
			? $course->get_installments_label()
			: esc_html( $args['text'] );
	} else {
		$text = ( 'Purchase' === $args['text'] )
			? sprintf(
				__( '%1$s - Purchase %2$s', 'wp-courseware' ),
				esc_attr( $course->get_price_label() ),
				esc_html( $course->get_course_title() )
			)
			: esc_html( $args['text'] );
	}
	return apply_filters( 'wpcw_add_to_cart_link', sprintf(
		'<a href="%s" class="%s" %s>%s</a>',
		$args['installments'] ? esc_url( wpcw_add_to_cart_url( $course->get_course_id(), true ) ) : esc_url( wpcw_add_to_cart_url( $course->get_course_id() ) ),
		esc_attr( isset( $args['class'] ) ? $args['class'] : 'wpcw-button' ),
		isset( $args['attributes'] ) ? wpcw_implode_html_attributes( $args['attributes'] ) : '',
		esc_html( $text )
	), $course, $args );
}
function wpcw_add_to_cart_link ( $ course , $ args = array ( ) , $ display_message = true , $ force = false ) { if ( ! $ course instanceof \ WPCW \ Models \ Course ) { return ; } if ( ! $ force && is_user_logged_in ( ) && $ course -> can_user_access ( get_current_user_id ( ) ) ) { if ( $ display_message ) { return apply_filters ( 'wpcw_course_already_enrolled_text' , sprintf ( __ ( '<p>You have already been enrolled into <strong>%s</strong>.</p>' , 'wp-courseware' ) , $ course -> get_course_title ( ) ) ) ; } else { return ; } } if ( ! $ force && wpcw_is_course_in_cart ( $ course -> get_course_id ( ) ) ) { return wpcw_get_checkout_link ( ) ; } $ defaults = array ( 'text' => esc_html__ ( 'Purchase' , 'wp-courseware' ) , 'quantity' => 1 , 'class' => implode ( ' ' , array_filter ( array ( 'wpcw-button wpcw-button-primary' , 'wpcw-add-to-cart' , apply_filters ( 'wpcw_cart_ajax_enabled' , true ) ? 'wpcw-ajax-add-to-cart' : '' , ) ) ) , 'attributes' => array ( 'data-course_id' => $ course -> get_course_id ( ) , 'rel' => 'nofollow' , ) , 'installments' => false , ) ; $ args = apply_filters ( 'wpcw_add_to_cart_args' , wp_parse_args ( $ args , $ defaults ) , $ course -> get_course_id ( ) ) ; if ( $ args [ 'installments' ] ) { $ args [ 'attributes' ] [ 'data-installments' ] = true ; $ args [ 'class' ] .= ' wpcw-add-to-cart-installments' ; $ text = ( 'Installments' === $ args [ 'text' ] ) ? $ course -> get_installments_label ( ) : esc_html ( $ args [ 'text' ] ) ; } else { $ text = ( 'Purchase' === $ args [ 'text' ] ) ? sprintf ( __ ( '%1$s - Purchase %2$s' , 'wp-courseware' ) , esc_attr ( $ course -> get_price_label ( ) ) , esc_html ( $ course -> get_course_title ( ) ) ) : esc_html ( $ args [ 'text' ] ) ; } return apply_filters ( 'wpcw_add_to_cart_link' , sprintf ( '<a href="%s" class="%s" %s>%s</a>' , $ args [ 'installments' ] ? esc_url ( wpcw_add_to_cart_url ( $ course -> get_course_id ( ) , true ) ) : esc_url ( wpcw_add_to_cart_url ( $ course -> get_course_id ( ) ) ) , esc_attr ( isset ( $ args [ 'class' ] ) ? $ args [ 'class' ] : 'wpcw-button' ) , isset ( $ args [ 'attributes' ] ) ? wpcw_implode_html_attributes ( $ args [ 'attributes' ] ) : '' , esc_html ( $ text ) ) , $ course , $ args ) ; }
Add to Cart Link.
Add to Cart Link .
/* translators: %s is the Course Title */ // Link Defaults. /* translators: %1$s - Course price, %2$s - Course title */ /* translators: %1$s - Course price, %2$s - Course title */