list = $quote_list; add_shortcode( 'bbquote_quote_list', array( $this, 'quote_list' ) ); add_shortcode( 'bbquote_button', array( $this, 'button' ) ); add_shortcode( 'bbquote_count', array( $this, 'count' ) ); } /** * Link to the quote page with the number of items: [bbquote_count label="Quote"]. * The number is filled in by frontend.js from the `bbquote_count` cookie, so the HTML is the same * for every visitor and safe for page caching. * * @param array $atts Attributes. * @return string */ public function count( $atts ) { $atts = shortcode_atts( array( 'label' => '' ), $atts, 'bbquote_count' ); return self::render_count( (string) $atts['label'] ); } /** * Counter HTML, shared by the shortcode and the block. * * @param string $label Label; '' = default. * @return string */ public static function render_count( $label = '' ) { ob_start(); wc_get_template( 'count.php', array( 'label' => '' !== trim( $label ) ? $label : __( 'Quote list', 'boring-quote' ), 'page_url' => Plugin::get_page_url(), ), 'boring-quote/', BBQUOTE_TEMPLATE_PATH ); return (string) ob_get_clean(); } /** * Quote page: list + form, or thank-you message. * * @return string */ public function quote_list() { ob_start(); if ( function_exists( 'wc_print_notices' ) ) { wc_print_notices(); } /** * Output at the top of the quote page (Pro: offer confirmation screens, responses). */ do_action( 'bbquote_quote_page_before' ); /** * Return true to render only what `bbquote_quote_page_before` printed (skip list and form). * * @param bool $takeover Takeover flag. */ if ( apply_filters( 'bbquote_quote_page_takeover', false ) ) { return (string) ob_get_clean(); } if ( isset( $_GET['bbquote-sent'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended wc_get_template( 'thank-you.php', array(), 'boring-quote/', BBQUOTE_TEMPLATE_PATH ); return (string) ob_get_clean(); } $is_empty = $this->list->is_empty(); echo '
'; echo '
'; wc_get_template( 'list.php', array( 'items' => $this->list->get_items() ), 'boring-quote/', BBQUOTE_TEMPLATE_PATH ); echo '
'; if ( ! $is_empty ) { echo '
'; wc_get_template( 'form.php', array( 'fields' => SubmitHandler::fields() ), 'boring-quote/', BBQUOTE_TEMPLATE_PATH ); echo '
'; } echo '
'; return (string) ob_get_clean(); } /** * Button anywhere: [bbquote_button product="123"]. * * @param array $atts Attributes. * @return string */ public function button( $atts ) { $atts = shortcode_atts( array( 'product' => 0 ), $atts, 'bbquote_button' ); $product = wc_get_product( $atts['product'] ? absint( $atts['product'] ) : get_the_ID() ); if ( ! $product ) { return ''; } $frontend = Plugin::instance()->frontend; return $frontend ? $frontend->render_button( $product ) : ''; } }