class_exists( '\WC_AJAX' ) ? \WC_AJAX::get_endpoint( 'cpod_quick_view' ) : '', 'prefetch' => (int) $s['prefetch'], 'next' => 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) && function_exists( 'wc_get_cart_url' ) ? wc_get_cart_url() : '', 'cart' => function_exists( 'wc_get_cart_url' ) ? wc_get_cart_url() : '', 'i18n' => array( 'added' => Settings::text( 'added' ), 'viewCart' => Settings::text( 'view_cart' ), 'close' => __( 'Close', 'cpod-kit' ), 'error' => __( 'Something went wrong. Please try again.', 'cpod-kit' ), 'prev' => __( 'Previous image', 'cpod-kit' ), 'next' => __( 'Next image', 'cpod-kit' ), ), ) ); // Small stylesheet on every page so the buttons never appear unstyled; the script only where a button is printed. wp_enqueue_style( self::HANDLE ); } public function card_start() { $this->printed = 0; } public function loop_button() { global $product; if ( $product instanceof \WC_Product && $this->printed !== $product->get_id() ) { $this->printed = $product->get_id(); $class = 'image' === Settings::get( 'position' ) ? 'is-image is-moved' : 'is-below'; echo self::html( $product, $class ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in html(). } } public function shortcode( $atts ) { $atts = shortcode_atts( array( 'id' => 0, 'text' => '' ), $atts, 'cpod_quick_view' ); $product_id = absint( $atts['id'] ); if ( ! $product_id ) { global $product; $product_id = $product instanceof \WC_Product ? $product->get_id() : 0; } $item = $product_id ? wc_get_product( $product_id ) : null; return wp_kses( $item ? self::html( $item, 'is-inline', (string) $atts['text'] ) : '', cpod_allowed_html() ); } /** * Quick view button. A real link to the product, so it still works without JavaScript. * * @param \WC_Product $product Product. * @param string $class Extra classes of the wrapper. * @param string $text Text instead of the setting. * @return string */ public static function html( $product, $class = '', $text = '' ) { wp_enqueue_script( self::HANDLE ); /* translators: %s: product name */ $aria = sprintf( __( 'Quick view: %s', 'cpod-kit' ), $product->get_name() ); $link = self::link( '', '' !== $text ? $text : Settings::text( 'text' ), $product->get_permalink(), array( 'data-cpod-qv' => $product->get_id(), 'aria-label' => $aria, 'rel' => 'nofollow' ) ); return '
' . $link . '
'; } /** * A button with the look settings of the Quick view button ('') or the details button ('d_'). * * @param string $prefix Settings prefix. * @param string $text Text. * @param string $href Link. * @param array $attrs Extra attributes. * @return string */ public static function link( $prefix, $text, $href, $attrs = array() ) { $s = Settings::all(); $style = $s[ $prefix . 'style' ]; $cls = 'cpod-qv-btn cpod-qv-btn--' . $style; $cls .= $s[ $prefix . 'full_width' ] && 'icon' !== $style ? ' is-full' : ''; $cls .= $s[ $prefix . 'uppercase' ] ? ' is-upper' : ''; $icon = self::icon( $s[ $prefix . 'icon' ], $s[ $prefix . 'icon_svg' ] ); if ( 'icon' === $style && '' === $icon ) { $icon = self::icon( 'eye' ); } $label = 'icon' === $style ? '' : '' . esc_html( $text ) . ''; $inner = $s[ $prefix . 'icon_after' ] ? $label . $icon : $icon . $label; $html = ' $value ) { $html .= ' ' . esc_attr( $name ) . '="' . esc_attr( $value ) . '"'; } return $html . '>' . $inner . ''; } /** Path data of the built-in icons (24×24, filled). */ public static function icon_paths() { return array( 'eye' => 'M12 5C6.5 5 2.4 9.4 1.2 11.4a1.2 1.2 0 0 0 0 1.2C2.4 14.6 6.5 19 12 19s9.6-4.4 10.8-6.4a1.2 1.2 0 0 0 0-1.2C21.6 9.4 17.5 5 12 5Zm0 11.5A4.5 4.5 0 1 1 12 7.5a4.5 4.5 0 0 1 0 9Zm0-7a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5Z', 'search' => 'M10.5 3a7.5 7.5 0 0 1 5.96 12.05l4.25 4.24a1 1 0 0 1-1.42 1.42l-4.24-4.25A7.5 7.5 0 1 1 10.5 3Zm0 2a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11Z', 'expand' => 'M4 3h5a1 1 0 0 1 0 2H6.41l4.3 4.29a1 1 0 0 1-1.42 1.42L5 6.41V9a1 1 0 0 1-2 0V4a1 1 0 0 1 1-1Zm11 0h5a1 1 0 0 1 1 1v5a1 1 0 1 1-2 0V6.41l-4.29 4.3a1 1 0 0 1-1.42-1.42L17.59 5H15a1 1 0 1 1 0-2ZM10.7 13.3a1 1 0 0 1 0 1.4L6.42 19H9a1 1 0 1 1 0 2H4a1 1 0 0 1-1-1v-5a1 1 0 1 1 2 0v2.59l4.29-4.3a1 1 0 0 1 1.42 0Zm2.6 0a1 1 0 0 1 1.4 0l4.3 4.29V15a1 1 0 1 1 2 0v5a1 1 0 0 1-1 1h-5a1 1 0 1 1 0-2h2.59l-4.3-4.29a1 1 0 0 1 0-1.42Z', 'plus' => 'M12 4a1 1 0 0 1 1 1v6h6a1 1 0 1 1 0 2h-6v6a1 1 0 1 1-2 0v-6H5a1 1 0 1 1 0-2h6V5a1 1 0 0 1 1-1Z', 'bag' => 'M12 2a4 4 0 0 1 4 4v1h2.1a1 1 0 0 1 1 .9l1.2 12A1 1 0 0 1 19.3 21H4.7a1 1 0 0 1-1-1.1l1.2-12a1 1 0 0 1 1-.9H8V6a4 4 0 0 1 4-4Zm-4 7H6.8l-1 10h12.4l-1-10H16v1.5a1 1 0 1 1-2 0V9h-4v1.5a1 1 0 1 1-2 0V9Zm4-5a2 2 0 0 0-2 2v1h4V6a2 2 0 0 0-2-2Z', 'arrow' => 'M13.3 5.3a1 1 0 0 1 1.4 0l6 6a1 1 0 0 1 0 1.4l-6 6a1 1 0 0 1-1.4-1.4l4.29-4.3H4a1 1 0 1 1 0-2h13.59l-4.3-4.3a1 1 0 0 1 0-1.4Z', ); } /** * Icon markup: a built-in icon, the custom SVG, or '' for none. * * @param string $name Icon name. * @param string $svg Custom SVG (already sanitised when saved). * @return string */ public static function icon( $name = 'eye', $svg = '' ) { if ( 'custom' === $name ) { $svg = trim( wp_kses( (string) $svg, Settings::svg_kses() ) ); return '' === $svg ? '' : ''; } $paths = self::icon_paths(); if ( ! isset( $paths[ $name ] ) ) { return ''; } return ''; } }