module_id = self::MODULE_ID;
// WooCommerce only.
$this->wc_only = true;
// Parent construct.
parent::__construct();
// Module section.
$this->module_section = 'convert-more';
// Module default settings.
$this->module_default_settings = array(
'button_type' => 'text',
'button_text' => __( 'Quick View', 'merchant' ),
'button_icon' => 'eye',
'button_position' => 'overlay',
'button-position-top' => 50,
'button-position-left' => 50,
'zoom_effect' => 1,
'show_quantity' => 1,
'place_product_description' => 'top',
'description_style' => 'short',
'place_product_image' => 'thumbs-at-left'
);
// Mount preview url.
$preview_url = site_url( '/' );
if ( function_exists( 'wc_get_page_id' ) ) {
$preview_url = get_permalink( wc_get_page_id( 'shop' ) );
}
// Module data.
$this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
$this->module_data[ 'preview_url' ] = $preview_url;
// Module options path.
$this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
// Is module preview page.
if ( is_admin() && parent::is_module_settings_page() ) {
self::$is_module_preview = true;
// Enqueue admin styles.
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
// Admin preview box.
add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
// Custom CSS.
// The custom CSS should be added here as well due to ensure preview box works properly.
add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) );
}
if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) {
// Init translations.
$this->init_translations();
}
if ( ! Merchant_Modules::is_module_active( self::MODULE_ID ) ) {
return;
}
// Return early if it's on admin but not in the respective module settings page.
if ( is_admin() && ! parent::is_module_settings_page() && ! defined( 'DOING_AJAX' ) ) {
return;
}
// Enqueue styles.
add_action( 'merchant_enqueue_before_main_css_js', array( $this, 'enqueue_css' ) );
// Enqueue scripts.
add_action( 'merchant_enqueue_after_main_css_js', array( $this, 'enqueue_scripts' ) );
// Localize script.
add_filter( 'merchant_localize_script', array( $this, 'localize_script' ) );
// Handle Botiga theme scripts for compatibility.
if ( defined( 'BOTIGA_PRO_URI' ) && defined( 'BOTIGA_PRO_VERSION' ) ) {
add_action( 'wp_enqueue_scripts', array( $this, 'modal_compatibility_with_botiga_theme' ) );
}
// Modal content ajax callback.
add_action( 'wp_ajax_merchant_quick_view_content', array( $this, 'modal_content_ajax_callback' ) );
add_action( 'wp_ajax_nopriv_merchant_quick_view_content', array( $this, 'modal_content_ajax_callback' ) );
// Button Position.
$button_position = Merchant_Admin_Options::get( self::MODULE_ID, 'button_position', 'overlay' );
if ( 'before' === $button_position ) {
add_action( 'woocommerce_after_shop_loop_item', array( $this, 'quick_view_button' ), 5 );
} elseif ( 'after' === $button_position ) {
add_action( 'woocommerce_after_shop_loop_item', array( $this, 'quick_view_button' ), 15 );
} elseif ( 'overlay' === $button_position ) {
if ( merchant_is_kadence_active() ) {
add_filter( 'kadence_archive_content_wrap_start', array( $this, 'add_quick_view_button' ) );
} else {
add_action( 'woocommerce_after_shop_loop_item', array( $this, 'quick_view_button' ), 15 );
}
}
// Inject quick view modal output on footer.
add_action( 'wp_footer', array( $this, 'modal_output' ) );
// Custom CSS.
add_filter( 'merchant_custom_css', array( $this, 'frontend_custom_css' ) );
}
/**
* Init translations.
*
* @return void
*/
public function init_translations() {
$settings = $this->get_module_settings();
if ( ! empty( $settings['button_text'] ) ) {
Merchant_Translator::register_string( $settings['button_text'], esc_html__( 'Quick view button text', 'merchant' ) );
}
}
/**
* Concatenate the quick view button with the content start wrap.
*
* @return string
*/
public function add_quick_view_button() {
return $this->quick_view_button() . '
';
}
/**
* Admin enqueue CSS.
*
* @return void
*/
public function admin_enqueue_css() {
$page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( 'merchant' === $page && self::MODULE_ID === $module ) {
wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/quick-view.min.css', [], MERCHANT_VERSION );
wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
}
}
/**
* Enqueue CSS.
*
* @return void
*/
public function enqueue_css() {
// Specific module styles.
wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/quick-view.min.css', array(), MERCHANT_VERSION );
}
/**
* Enqueue scripts.
*
* @return void
*/
public function enqueue_scripts() {
wp_enqueue_script( 'zoom' );
wp_enqueue_script( 'flexslider' );
wp_enqueue_script( 'wc-single-product' );
wp_enqueue_script( 'wc-add-to-cart-variation' );
// Register and enqueue the main module script.
wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/quick-view.min.js', array(), MERCHANT_VERSION, true );
}
/**
* Localize script with module settings.
*
* @param array $setting The merchant global object setting parameter.
* @return array $setting The merchant global object setting parameter.
*/
public function localize_script( $setting ) {
$module_settings = $this->get_module_settings();
$setting[ 'quick_view' ] = true;
$setting[ 'quick_view_zoom' ] = $module_settings[ 'zoom_effect' ];
return $setting;
}
/**
* Enqueue botiga theme scripts.
*
* @return void
*/
public function modal_compatibility_with_botiga_theme() {
if ( ! wp_script_is( 'botiga-product-swatch' ) ) {
wp_enqueue_script( 'botiga-product-swatch', BOTIGA_PRO_URI . 'assets/js/botiga-product-swatch.min.js', array(), BOTIGA_PRO_VERSION, true );
}
if ( ! wp_script_is( 'botiga-checkout-quantity-input' ) ) {
wp_enqueue_script( 'botiga-checkout-quantity-input', BOTIGA_PRO_URI . 'assets/js/botiga-checkout-quantity-input.min.js', array( 'jquery' ), BOTIGA_PRO_VERSION, true );
}
}
/**
* Render admin preview
*
* @param Merchant_Admin_Preview $preview
* @param string $module
*
* @return Merchant_Admin_Preview
*/
public function render_admin_preview( $preview, $module ) {
if ( self::MODULE_ID === $module ) {
ob_start();
self::admin_preview_content();
$content = ob_get_clean();
// HTML.
$preview->set_html( $content );
// Button Type.
$preview->set_class( 'button_type', '.merchant-quick-view-button', array( 'icon', 'icon-text', 'text' ) );
// Button Text.
$preview->set_text( 'button_text', '.button-text' );
// Button Icon.
$preview->set_svg_icon( 'button_icon', '.quick-view-icon' );
// Button Position.
$preview->set_class( 'button_position', '.merchant-quick-view-preview', array( 'before', 'after', 'overlay' ) );
}
return $preview;
}
/**
* Admin preview content.
*
* @return void
*/
public function admin_preview_content() {
$settings = $this->get_module_settings();
?>
get_module_settings();
?>
absint( $_POST['product_id'] )
);
global $product;
$settings = $this->get_module_settings();
$product = wc_get_product( $args['product_id'] );
if ( is_wp_error( $product ) || empty( $product ) ) {
wp_send_json_error();
}
$product_id = $product->get_id();
$hide_quantity = ( empty( $settings[ 'show_quantity' ] ) ) ? 'merchant-hide-quantity' : '';
ob_start();
?>
>
get_title() ); ?>
get_average_rating() ) : ?>
get_average_rating() ), merchant_kses_allowed_tags() ); ?>
get_price_html(), merchant_kses_allowed_tags() ); ?>
get_description() ); ?>
get_short_description() ); ?>
get_description() ); ?>
get_short_description() ); ?>
get_module_settings();
?>
get_module_settings();
$product_id = $product->get_id();
$button_text_html = '';
$button_icon_html = '';
if ( 'icon' === $settings[ 'button_type' ] || 'icon-text' === $settings[ 'button_type' ] ) {
$button_icon_html = Merchant_SVG_Icons::get_svg_icon( $settings[ 'button_icon' ] );
}
if ( 'text' === $settings[ 'button_type' ] || 'icon-text' === $settings[ 'button_type' ] ) {
$button_text_html = '
' . Merchant_Translator::translate( $settings[ 'button_text' ] ) . '';
}
?>
get_module_custom_css();
return $css;
}
/**
* Frontend custom CSS.
*
* @param string $css The custom CSS.
* @return string $css The custom CSS.
*/
public function frontend_custom_css( $css ) {
$css .= $this->get_module_custom_css();
return $css;
}
}
// Initialize the module.
add_action( 'init', function() {
new Merchant_Quick_View();
} );