Plugin Directory

Changeset 3388695


Ignore:
Timestamp:
11/03/2025 08:55:51 AM (4 months ago)
Author:
spiraclethemes
Message:

updating to ver 1.5.8

Location:
spiraclethemes-site-library
Files:
180 added
8 edited

Legend:

Unmodified
Added
Removed
  • spiraclethemes-site-library/trunk/Changelogs.txt

    r3360556 r3388695  
    11
    22== Changelog ==
     3
     4== 1.5.8 ==
     5- Fixed some issues
    36
    47== 1.5.7 ==
  • spiraclethemes-site-library/trunk/README.txt

    r3360556 r3388695  
    33Contributors: spiraclethemes
    44Tags: spiraclethemes, demo, import, themes
    5 Stable tag: 1.5.7
     5Stable tag: 1.5.8
    66Requires at least: 5.0
    77Requires PHP: 5.6
  • spiraclethemes-site-library/trunk/inc/own-shop-functions.php

    r3327924 r3388695  
    8787                  'name'     => 'WooCommerce',
    8888                  'slug'     => 'woocommerce',
    89                   'required' => true,
    90                 ],
    91                 [
    92                   'name'     => 'YITH WooCommerce Quick View',
    93                   'slug'     => 'yith-woocommerce-quick-view',
    9489                  'required' => true,
    9590                ],
     
    446441    add_shortcode('recentblog', 'spiraclethemes_site_library_own_shop_recentblog');
    447442}
     443
     444/**
     445 * Quick View Functions
     446 */
     447
     448/**
     449 * Add Quick View Button to WooCommerce Product Loop
     450 */
     451if( !function_exists('spiraclethemes_site_library_own_shop_add_quick_view_button') ) {
     452function spiraclethemes_site_library_own_shop_add_quick_view_button() {
     453    global $product;
     454    if ( $product && is_a( $product, 'WC_Product' ) ) {
     455        echo '<a href="#" class="own-shop-quick-view-btn" data-product-id="' . esc_attr( $product->get_id() ) . '" data-product-type="' . esc_attr( $product->get_type() ) . '" aria-label="' . esc_attr__( 'Quick View', 'spiraclethemes-site-library' ) . '"></a>';
     456    }
     457}
     458}
     459
     460/**
     461 * Enqueue Quick View Scripts
     462 */
     463if( !function_exists('spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts') ) {
     464    function spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts() {
     465        wp_enqueue_script( 'own-shop-quick-view', plugin_dir_url( __FILE__ ) . '../js/own-shop-quick-view.js', array( 'jquery' ), '1.0.0', true );
     466        wp_localize_script( 'own-shop-quick-view', 'own_shop_quick_view_ajax', array(
     467            'ajax_url' => admin_url( 'admin-ajax.php' ),
     468            'nonce' => wp_create_nonce( 'own_shop_quick_view_nonce' )
     469        ));
     470        wp_enqueue_style( 'own-shop-quick-view', plugin_dir_url( __FILE__ ) . '../css/own-shop-quick-view.css', array(), '1.0.0' );
     471    }
     472    add_action( 'wp_enqueue_scripts', 'spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts' );
     473}
     474
     475/**
     476 * AJAX Handler for Quick View
     477 */
     478if( !function_exists('spiraclethemes_site_library_own_shop_quick_view_ajax_handler') ) {
     479    function spiraclethemes_site_library_own_shop_quick_view_ajax_handler() {
     480        check_ajax_referer( 'own_shop_quick_view_nonce', 'nonce' );
     481
     482        $product_id = intval( $_POST['product_id'] );
     483        $product = wc_get_product( $product_id );
     484
     485        if ( !$product ) {
     486            wp_die( esc_html__( 'Product not found.', 'spiraclethemes-site-library' ) );
     487        }
     488
     489        ob_start();
     490        ?>
     491        <div class="own-shop-quick-view-modal">
     492            <div class="quick-view-content">
     493                <button class="quick-view-close" onclick="closeOwnShopQuickView()" aria-label="Close">
     494                    <i class="las la-times-circle"></i>
     495                </button>
     496                <div class="quick-view-body">
     497                    <div class="quick-view-images-section">
     498                        <?php
     499                        $attachment_ids = $product->get_gallery_image_ids();
     500                        $main_image_url = has_post_thumbnail( $product_id ) ? get_the_post_thumbnail_url( $product_id, 'large' ) : wc_placeholder_img_src();
     501                        ?>
     502                        <img id="quick-view-main-image" class="quick-view-main-image" src="<?php echo esc_url( $main_image_url ); ?>" alt="<?php echo esc_attr( $product->get_name() ); ?>">
     503
     504                        <?php if ( count( $attachment_ids ) > 1 || has_post_thumbnail( $product_id ) ) : ?>
     505                        <div class="quick-view-thumbnails">
     506                            <?php
     507                            if ( has_post_thumbnail( $product_id ) ) {
     508                                $thumbnail_url = get_the_post_thumbnail_url( $product_id, 'thumbnail' );
     509                                echo '<img class="thumbnail active" src="' . esc_url( $thumbnail_url ) . '" alt="Thumbnail" onclick="changeQuickViewImage(\'' . esc_js( $thumbnail_url ) . '\', this)">';
     510                            }
     511                            if ( $attachment_ids ) {
     512                                foreach ( $attachment_ids as $attachment_id ) {
     513                                    $thumbnail_url = wp_get_attachment_image_url( $attachment_id, 'thumbnail' );
     514                                    $large_url = wp_get_attachment_image_url( $attachment_id, 'large' );
     515                                    echo '<img class="thumbnail" src="' . esc_url( $thumbnail_url ) . '" alt="Thumbnail" onclick="changeQuickViewImage(\'' . esc_js( $large_url ) . '\', this)">';
     516                                }
     517                            }
     518                            ?>
     519                        </div>
     520                        <?php endif; ?>
     521                    </div>
     522                    <div class="quick-view-details">
     523                        <h2 class="quick-view-title"><?php echo esc_html( $product->get_name() ); ?></h2>
     524
     525                        <div class="quick-view-rating">
     526                            <?php
     527                            $rating_count = $product->get_rating_count();
     528                            $review_count = $product->get_review_count();
     529                            $average = $product->get_average_rating();
     530                            ?>
     531                            <?php echo wc_get_rating_html( $average, $rating_count ); ?>
     532                            <?php if ( comments_open() && $review_count ) : ?>
     533                                <span class="modal-reviews"><?php printf( _n( '(%s review)', '(%s reviews)', $review_count, 'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?></span>
     534                            <?php endif ?>
     535                        </div>
     536
     537                        <div class="quick-view-price"><?php echo $product->get_price_html(); ?></div>
     538
     539                        <div class="quick-view-description">
     540                            <?php echo wp_kses_post( $product->get_short_description() ? $product->get_short_description() : $product->get_description() ); ?>
     541                        </div>
     542
     543                        <!-- Stock Status -->
     544                        <div class="modal-stock"><?php echo esc_html( $product->is_in_stock() ? 'In Stock' : 'Out of Stock' ); ?></div>
     545
     546                        <div class="quick-view-quantity">
     547                            <span class="quantity-label"><?php esc_html_e('Quantity:', 'woocommerce'); ?></span>
     548                            <div class="quantity-input">
     549                                <button class="quantity-btn" onclick="decreaseQuickViewQuantity()">-</button>
     550                                <input type="number" class="quantity-value" id="quick-view-quantity" value="1" min="1" readonly>
     551                                <button class="quantity-btn" onclick="increaseQuickViewQuantity()">+</button>
     552                            </div>
     553                        </div>
     554
     555                        <button class="modal-add-to-cart" onclick="addQuickViewToCart(<?php echo esc_js($product_id); ?>)">
     556                            <i class="fas fa-shopping-cart"></i> <?php echo esc_html($product->single_add_to_cart_text()); ?>
     557                        </button>
     558
     559                        <!-- Meta Information -->
     560                        <div class="modal-meta">
     561                            <div><span><?php esc_html_e('SKU:', 'spiraclethemes-site-library'); ?></span> <span><?php echo esc_html( $product->get_sku() ? $product->get_sku() : esc_html__('N/A', 'spiraclethemes-site-library') ); ?></span></div>
     562                            <div><span><?php esc_html_e('Category:', 'spiraclethemes-site-library'); ?></span>
     563                                <?php
     564                                $categories = wp_get_post_terms( $product_id, 'product_cat' );
     565                                $category_names = array();
     566                                foreach ( $categories as $category ) {
     567                                    $category_names[] = esc_html( $category->name );
     568                                }
     569                                echo '<span>' . implode( ', ', $category_names ) . '</span>';
     570                                ?>
     571                            </div>
     572                        </div>
     573                    </div>
     574                </div>
     575            </div>
     576        </div>
     577        <?php
     578        $content = ob_get_clean();
     579
     580        wp_send_json_success( $content );
     581    }
     582    add_action( 'wp_ajax_own_shop_quick_view', 'spiraclethemes_site_library_own_shop_quick_view_ajax_handler' );
     583    add_action( 'wp_ajax_nopriv_own_shop_quick_view', 'spiraclethemes_site_library_own_shop_quick_view_ajax_handler' );
     584}
     585
     586/**
     587 * AJAX Handler for Quick View Add to Cart
     588 */
     589if( !function_exists('spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax') ) {
     590    function spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax() {
     591        check_ajax_referer( 'own_shop_quick_view_nonce', 'security' );
     592
     593        $product_id = intval( $_POST['product_id'] );
     594        $quantity = intval( $_POST['quantity'] );
     595        $variation_id = isset( $_POST['variation_id'] ) ? intval( $_POST['variation_id'] ) : 0;
     596        $variations = isset( $_POST['variation'] ) ? $_POST['variation'] : array();
     597
     598        if ( ! $product_id || $quantity < 1 ) {
     599            wp_send_json_error( __( 'Invalid product or quantity.', 'spiraclethemes-site-library' ) );
     600        }
     601
     602        $product = wc_get_product( $product_id );
     603
     604        if ( ! $product ) {
     605            wp_send_json_error( __( 'Product not found.', 'spiraclethemes-site-library' ) );
     606        }
     607
     608        // Handle variable products
     609        if ( $product->is_type( 'variable' ) ) {
     610            if ( ! $variation_id ) {
     611                wp_send_json_error( __( 'Please select product options.', 'spiraclethemes-site-library' ) );
     612            }
     613
     614            $variation = wc_get_product( $variation_id );
     615            if ( ! $variation || ! $variation->exists() || ! $variation->is_in_stock() ) {
     616                wp_send_json_error( __( 'Invalid variation selected.', 'spiraclethemes-site-library' ) );
     617            }
     618
     619            $product_id = $variation_id;
     620        }
     621
     622        // Check if product is in stock
     623        if ( ! $product->is_in_stock() ) {
     624            wp_send_json_error( __( 'Sorry, this product is out of stock.', 'spiraclethemes-site-library' ) );
     625        }
     626
     627        // Check stock quantity
     628        if ( ! $product->has_enough_stock( $quantity ) ) {
     629            wp_send_json_error( sprintf( __( 'Sorry, we do not have enough "%s" in stock to fulfill your order.', 'woocommerce' ), $product->get_name() ) );
     630        }
     631
     632        // Add to cart
     633        $cart_item_key = WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations );
     634
     635        if ( ! $cart_item_key ) {
     636            wp_send_json_error( __( 'Failed to add product to cart.', 'spiraclethemes-site-library' ) );
     637        }
     638
     639        // Return success response
     640        wp_send_json_success( array(
     641            'cart_hash' => WC()->cart->get_cart_hash(),
     642            'fragments' => apply_filters( 'woocommerce_add_to_cart_fragments', array() ),
     643            'cart_url' => wc_get_cart_url(),
     644            'message' => sprintf( __( '"%s" has been added to your cart.', 'woocommerce' ), $product->get_name() ),
     645        ) );
     646    }
     647    add_action( 'wp_ajax_own_shop_quick_view_add_to_cart', 'spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax' );
     648    add_action( 'wp_ajax_nopriv_own_shop_quick_view_add_to_cart', 'spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax' );
     649}
     650
     651/**
     652 * Add Quick View Button to Product Actions
     653 */
     654if( !function_exists('spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop') ) {
     655    function spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop() {
     656        add_action( 'woocommerce_after_shop_loop_item', 'spiraclethemes_site_library_own_shop_add_quick_view_button', 15 );
     657    }
     658    add_action( 'woocommerce_init', 'spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop' );
     659}
  • spiraclethemes-site-library/trunk/inc/own-shop-lite-functions.php

    r3327924 r3388695  
    8383                  'name'     => 'WooCommerce',
    8484                  'slug'     => 'woocommerce',
    85                   'required' => true,
    86                 ],
    87                 [
    88                   'name'     => 'YITH WooCommerce Quick View',
    89                   'slug'     => 'yith-woocommerce-quick-view',
    9085                  'required' => true,
    9186                ],
     
    442437    add_shortcode('recentblog', 'spiraclethemes_site_library_own_shop_recentblog');
    443438}
     439
     440/**
     441 * Quick View Functions
     442 */
     443
     444/**
     445 * Add Quick View Button to WooCommerce Product Loop
     446 */
     447if( !function_exists('spiraclethemes_site_library_own_shop_add_quick_view_button') ) {
     448function spiraclethemes_site_library_own_shop_add_quick_view_button() {
     449    global $product;
     450    if ( $product && is_a( $product, 'WC_Product' ) ) {
     451        echo '<a href="#" class="own-shop-quick-view-btn" data-product-id="' . esc_attr( $product->get_id() ) . '" data-product-type="' . esc_attr( $product->get_type() ) . '" aria-label="' . esc_attr__( 'Quick View', 'spiraclethemes-site-library' ) . '"></a>';
     452    }
     453}
     454}
     455
     456/**
     457 * Enqueue Quick View Scripts
     458 */
     459if( !function_exists('spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts') ) {
     460    function spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts() {
     461        wp_enqueue_script( 'own-shop-quick-view', plugin_dir_url( __FILE__ ) . '../js/own-shop-quick-view.js', array( 'jquery' ), '1.0.0', true );
     462        wp_localize_script( 'own-shop-quick-view', 'own_shop_quick_view_ajax', array(
     463            'ajax_url' => admin_url( 'admin-ajax.php' ),
     464            'nonce' => wp_create_nonce( 'own_shop_quick_view_nonce' )
     465        ));
     466        // Enqueue parent quick view CSS
     467        wp_enqueue_style( 'own-shop-quick-view', plugin_dir_url( __FILE__ ) . '../css/own-shop-quick-view.css', array(), '1.0.0' );
     468        // Enqueue own-store specific CSS
     469        wp_enqueue_style( 'own-store-quick-view', plugin_dir_url( __FILE__ ) . '../css/own-store-quick-view.css', array('own-shop-quick-view'), '1.0.0' );
     470    }
     471    add_action( 'wp_enqueue_scripts', 'spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts' );
     472}
     473
     474/**
     475 * AJAX Handler for Quick View
     476 */
     477if( !function_exists('spiraclethemes_site_library_own_shop_quick_view_ajax_handler') ) {
     478    function spiraclethemes_site_library_own_shop_quick_view_ajax_handler() {
     479        check_ajax_referer( 'own_shop_quick_view_nonce', 'nonce' );
     480
     481        $product_id = intval( $_POST['product_id'] );
     482        $product = wc_get_product( $product_id );
     483
     484        if ( !$product ) {
     485            wp_die( esc_html__( 'Product not found.', 'spiraclethemes-site-library' ) );
     486        }
     487
     488        ob_start();
     489        ?>
     490        <div class="own-shop-quick-view-modal">
     491            <div class="quick-view-content">
     492                <button class="quick-view-close" onclick="closeOwnShopQuickView()" aria-label="Close">
     493                    <i class="las la-times-circle"></i>
     494                </button>
     495                <div class="quick-view-body">
     496                    <div class="quick-view-images-section">
     497                        <?php
     498                        $attachment_ids = $product->get_gallery_image_ids();
     499                        $main_image_url = has_post_thumbnail( $product_id ) ? get_the_post_thumbnail_url( $product_id, 'large' ) : wc_placeholder_img_src();
     500                        ?>
     501                        <img id="quick-view-main-image" class="quick-view-main-image" src="<?php echo esc_url( $main_image_url ); ?>" alt="<?php echo esc_attr( $product->get_name() ); ?>">
     502
     503                        <?php if ( count( $attachment_ids ) > 1 || has_post_thumbnail( $product_id ) ) : ?>
     504                        <div class="quick-view-thumbnails">
     505                            <?php
     506                            if ( has_post_thumbnail( $product_id ) ) {
     507                                $thumbnail_url = get_the_post_thumbnail_url( $product_id, 'thumbnail' );
     508                                echo '<img class="thumbnail active" src="' . esc_url( $thumbnail_url ) . '" alt="Thumbnail" onclick="changeQuickViewImage(\'' . esc_js( $thumbnail_url ) . '\', this)">';
     509                            }
     510                            if ( $attachment_ids ) {
     511                                foreach ( $attachment_ids as $attachment_id ) {
     512                                    $thumbnail_url = wp_get_attachment_image_url( $attachment_id, 'thumbnail' );
     513                                    $large_url = wp_get_attachment_image_url( $attachment_id, 'large' );
     514                                    echo '<img class="thumbnail" src="' . esc_url( $thumbnail_url ) . '" alt="Thumbnail" onclick="changeQuickViewImage(\'' . esc_js( $large_url ) . '\', this)">';
     515                                }
     516                            }
     517                            ?>
     518                        </div>
     519                        <?php endif; ?>
     520                    </div>
     521                    <div class="quick-view-details">
     522                        <h2 class="quick-view-title"><?php echo esc_html( $product->get_name() ); ?></h2>
     523
     524                        <div class="quick-view-rating">
     525                            <?php
     526                            $rating_count = $product->get_rating_count();
     527                            $review_count = $product->get_review_count();
     528                            $average = $product->get_average_rating();
     529                            ?>
     530                            <?php echo wc_get_rating_html( $average, $rating_count ); ?>
     531                            <?php if ( comments_open() && $review_count ) : ?>
     532                                <span class="modal-reviews"><?php printf( _n( '(%s review)', '(%s reviews)', $review_count, 'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?></span>
     533                            <?php endif ?>
     534                        </div>
     535
     536                        <div class="quick-view-price"><?php echo $product->get_price_html(); ?></div>
     537
     538                        <div class="quick-view-description">
     539                            <?php echo wp_kses_post( $product->get_short_description() ? $product->get_short_description() : $product->get_description() ); ?>
     540                        </div>
     541
     542                        <!-- Stock Status -->
     543                        <div class="modal-stock"><?php echo esc_html( $product->is_in_stock() ? 'In Stock' : 'Out of Stock' ); ?></div>
     544
     545                        <div class="quick-view-quantity">
     546                            <span class="quantity-label"><?php esc_html_e('Quantity:', 'woocommerce'); ?></span>
     547                            <div class="quantity-input">
     548                                <button class="quantity-btn" onclick="decreaseQuickViewQuantity()">-</button>
     549                                <input type="number" class="quantity-value" id="quick-view-quantity" value="1" min="1" readonly>
     550                                <button class="quantity-btn" onclick="increaseQuickViewQuantity()">+</button>
     551                            </div>
     552                        </div>
     553
     554                        <button class="modal-add-to-cart" onclick="addQuickViewToCart(<?php echo esc_js($product_id); ?>)">
     555                            <i class="fas fa-shopping-cart"></i> <?php echo esc_html($product->single_add_to_cart_text()); ?>
     556                        </button>
     557
     558                        <!-- Meta Information -->
     559                        <div class="modal-meta">
     560                            <div><span><?php esc_html_e('SKU:', 'spiraclethemes-site-library'); ?></span> <span><?php echo esc_html( $product->get_sku() ? $product->get_sku() : esc_html__('N/A', 'spiraclethemes-site-library') ); ?></span></div>
     561                            <div><span><?php esc_html_e('Category:', 'spiraclethemes-site-library'); ?></span>
     562                                <?php
     563                                $categories = wp_get_post_terms( $product_id, 'product_cat' );
     564                                $category_names = array();
     565                                foreach ( $categories as $category ) {
     566                                    $category_names[] = esc_html( $category->name );
     567                                }
     568                                echo '<span>' . implode( ', ', $category_names ) . '</span>';
     569                                ?>
     570                            </div>
     571                        </div>
     572                    </div>
     573                </div>
     574            </div>
     575        </div>
     576        <?php
     577        $content = ob_get_clean();
     578
     579        wp_send_json_success( $content );
     580    }
     581    add_action( 'wp_ajax_own_shop_quick_view', 'spiraclethemes_site_library_own_shop_quick_view_ajax_handler' );
     582    add_action( 'wp_ajax_nopriv_own_shop_quick_view', 'spiraclethemes_site_library_own_shop_quick_view_ajax_handler' );
     583}
     584
     585/**
     586 * AJAX Handler for Quick View Add to Cart
     587 */
     588if( !function_exists('spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax') ) {
     589    function spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax() {
     590        check_ajax_referer( 'own_shop_quick_view_nonce', 'security' );
     591
     592        $product_id = intval( $_POST['product_id'] );
     593        $quantity = intval( $_POST['quantity'] );
     594        $variation_id = isset( $_POST['variation_id'] ) ? intval( $_POST['variation_id'] ) : 0;
     595        $variations = isset( $_POST['variation'] ) ? $_POST['variation'] : array();
     596
     597        if ( ! $product_id || $quantity < 1 ) {
     598            wp_send_json_error( __( 'Invalid product or quantity.', 'spiraclethemes-site-library' ) );
     599        }
     600
     601        $product = wc_get_product( $product_id );
     602
     603        if ( ! $product ) {
     604            wp_send_json_error( __( 'Product not found.', 'spiraclethemes-site-library' ) );
     605        }
     606
     607        // Handle variable products
     608        if ( $product->is_type( 'variable' ) ) {
     609            if ( ! $variation_id ) {
     610                wp_send_json_error( __( 'Please select product options.', 'spiraclethemes-site-library' ) );
     611            }
     612
     613            $variation = wc_get_product( $variation_id );
     614            if ( ! $variation || ! $variation->exists() || ! $variation->is_in_stock() ) {
     615                wp_send_json_error( __( 'Invalid variation selected.', 'spiraclethemes-site-library' ) );
     616            }
     617
     618            $product_id = $variation_id;
     619        }
     620
     621        // Check if product is in stock
     622        if ( ! $product->is_in_stock() ) {
     623            wp_send_json_error( __( 'Sorry, this product is out of stock.', 'spiraclethemes-site-library' ) );
     624        }
     625
     626        // Check stock quantity
     627        if ( ! $product->has_enough_stock( $quantity ) ) {
     628            wp_send_json_error( sprintf( __( 'Sorry, we do not have enough "%s" in stock to fulfill your order.', 'woocommerce' ), $product->get_name() ) );
     629        }
     630
     631        // Add to cart
     632        $cart_item_key = WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations );
     633
     634        if ( ! $cart_item_key ) {
     635            wp_send_json_error( __( 'Failed to add product to cart.', 'spiraclethemes-site-library' ) );
     636        }
     637
     638        // Return success response
     639        wp_send_json_success( array(
     640            'cart_hash' => WC()->cart->get_cart_hash(),
     641            'fragments' => apply_filters( 'woocommerce_add_to_cart_fragments', array() ),
     642            'cart_url' => wc_get_cart_url(),
     643            'message' => sprintf( __( '"%s" has been added to your cart.', 'woocommerce' ), $product->get_name() ),
     644        ) );
     645    }
     646    add_action( 'wp_ajax_own_shop_quick_view_add_to_cart', 'spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax' );
     647    add_action( 'wp_ajax_nopriv_own_shop_quick_view_add_to_cart', 'spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax' );
     648}
     649
     650/**
     651 * Add Quick View Button to Product Actions
     652 */
     653if( !function_exists('spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop') ) {
     654    function spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop() {
     655        add_action( 'woocommerce_after_shop_loop_item', 'spiraclethemes_site_library_own_shop_add_quick_view_button', 15 );
     656    }
     657    add_action( 'woocommerce_init', 'spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop' );
     658}
  • spiraclethemes-site-library/trunk/inc/own-shop-trend-functions.php

    r3166955 r3388695  
    8686                ],
    8787                [
    88                   'name'     => 'YITH WooCommerce Quick View',
    89                   'slug'     => 'yith-woocommerce-quick-view',
    90                   'required' => true,
    91                 ],
    92                 [
    9388                  'name'     => 'Contact Form 7',
    9489                  'slug'     => 'contact-form-7',
  • spiraclethemes-site-library/trunk/inc/own-shope-functions.php

    r3327924 r3388695  
    8383                  'name'     => 'WooCommerce',
    8484                  'slug'     => 'woocommerce',
    85                   'required' => true,
    86                 ],
    87                 [
    88                   'name'     => 'YITH WooCommerce Quick View',
    89                   'slug'     => 'yith-woocommerce-quick-view',
    9085                  'required' => true,
    9186                ],
     
    442437    add_shortcode('recentblog', 'spiraclethemes_site_library_own_shop_recentblog');
    443438}
     439
     440/**
     441 * Quick View Functions
     442 */
     443
     444/**
     445 * Add Quick View Button to WooCommerce Product Loop
     446 */
     447if( !function_exists('spiraclethemes_site_library_own_shop_add_quick_view_button') ) {
     448function spiraclethemes_site_library_own_shop_add_quick_view_button() {
     449    global $product;
     450    if ( $product && is_a( $product, 'WC_Product' ) ) {
     451        echo '<a href="#" class="own-shop-quick-view-btn" data-product-id="' . esc_attr( $product->get_id() ) . '" data-product-type="' . esc_attr( $product->get_type() ) . '" aria-label="' . esc_attr__( 'Quick View', 'spiraclethemes-site-library' ) . '"></a>';
     452    }
     453}
     454}
     455
     456/**
     457 * Enqueue Quick View Scripts
     458 */
     459if( !function_exists('spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts') ) {
     460    function spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts() {
     461        wp_enqueue_script( 'own-shop-quick-view', plugin_dir_url( __FILE__ ) . '../js/own-shop-quick-view.js', array( 'jquery' ), '1.0.0', true );
     462        wp_localize_script( 'own-shop-quick-view', 'own_shop_quick_view_ajax', array(
     463            'ajax_url' => admin_url( 'admin-ajax.php' ),
     464            'nonce' => wp_create_nonce( 'own_shop_quick_view_nonce' )
     465        ));
     466        // Enqueue parent quick view CSS
     467        wp_enqueue_style( 'own-shop-quick-view', plugin_dir_url( __FILE__ ) . '../css/own-shop-quick-view.css', array(), '1.0.0' );
     468        // Enqueue own-store specific CSS
     469        wp_enqueue_style( 'own-store-quick-view', plugin_dir_url( __FILE__ ) . '../css/own-store-quick-view.css', array('own-shop-quick-view'), '1.0.0' );
     470    }
     471    add_action( 'wp_enqueue_scripts', 'spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts' );
     472}
     473
     474/**
     475 * AJAX Handler for Quick View
     476 */
     477if( !function_exists('spiraclethemes_site_library_own_shop_quick_view_ajax_handler') ) {
     478    function spiraclethemes_site_library_own_shop_quick_view_ajax_handler() {
     479        check_ajax_referer( 'own_shop_quick_view_nonce', 'nonce' );
     480
     481        $product_id = intval( $_POST['product_id'] );
     482        $product = wc_get_product( $product_id );
     483
     484        if ( !$product ) {
     485            wp_die( esc_html__( 'Product not found.', 'spiraclethemes-site-library' ) );
     486        }
     487
     488        ob_start();
     489        ?>
     490        <div class="own-shop-quick-view-modal">
     491            <div class="quick-view-content">
     492                <button class="quick-view-close" onclick="closeOwnShopQuickView()" aria-label="Close">
     493                    <i class="las la-times-circle"></i>
     494                </button>
     495                <div class="quick-view-body">
     496                    <div class="quick-view-images-section">
     497                        <?php
     498                        $attachment_ids = $product->get_gallery_image_ids();
     499                        $main_image_url = has_post_thumbnail( $product_id ) ? get_the_post_thumbnail_url( $product_id, 'large' ) : wc_placeholder_img_src();
     500                        ?>
     501                        <img id="quick-view-main-image" class="quick-view-main-image" src="<?php echo esc_url( $main_image_url ); ?>" alt="<?php echo esc_attr( $product->get_name() ); ?>">
     502
     503                        <?php if ( count( $attachment_ids ) > 1 || has_post_thumbnail( $product_id ) ) : ?>
     504                        <div class="quick-view-thumbnails">
     505                            <?php
     506                            if ( has_post_thumbnail( $product_id ) ) {
     507                                $thumbnail_url = get_the_post_thumbnail_url( $product_id, 'thumbnail' );
     508                                echo '<img class="thumbnail active" src="' . esc_url( $thumbnail_url ) . '" alt="Thumbnail" onclick="changeQuickViewImage(\'' . esc_js( $thumbnail_url ) . '\', this)">';
     509                            }
     510                            if ( $attachment_ids ) {
     511                                foreach ( $attachment_ids as $attachment_id ) {
     512                                    $thumbnail_url = wp_get_attachment_image_url( $attachment_id, 'thumbnail' );
     513                                    $large_url = wp_get_attachment_image_url( $attachment_id, 'large' );
     514                                    echo '<img class="thumbnail" src="' . esc_url( $thumbnail_url ) . '" alt="Thumbnail" onclick="changeQuickViewImage(\'' . esc_js( $large_url ) . '\', this)">';
     515                                }
     516                            }
     517                            ?>
     518                        </div>
     519                        <?php endif; ?>
     520                    </div>
     521                    <div class="quick-view-details">
     522                        <h2 class="quick-view-title"><?php echo esc_html( $product->get_name() ); ?></h2>
     523
     524                        <div class="quick-view-rating">
     525                            <?php
     526                            $rating_count = $product->get_rating_count();
     527                            $review_count = $product->get_review_count();
     528                            $average = $product->get_average_rating();
     529                            ?>
     530                            <?php echo wc_get_rating_html( $average, $rating_count ); ?>
     531                            <?php if ( comments_open() && $review_count ) : ?>
     532                                <span class="modal-reviews"><?php printf( _n( '(%s review)', '(%s reviews)', $review_count, 'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?></span>
     533                            <?php endif ?>
     534                        </div>
     535
     536                        <div class="quick-view-price"><?php echo $product->get_price_html(); ?></div>
     537
     538                        <div class="quick-view-description">
     539                            <?php echo wp_kses_post( $product->get_short_description() ? $product->get_short_description() : $product->get_description() ); ?>
     540                        </div>
     541
     542                        <!-- Stock Status -->
     543                        <div class="modal-stock"><?php echo esc_html( $product->is_in_stock() ? 'In Stock' : 'Out of Stock' ); ?></div>
     544
     545                        <div class="quick-view-quantity">
     546                            <span class="quantity-label"><?php esc_html_e('Quantity:', 'woocommerce'); ?></span>
     547                            <div class="quantity-input">
     548                                <button class="quantity-btn" onclick="decreaseQuickViewQuantity()">-</button>
     549                                <input type="number" class="quantity-value" id="quick-view-quantity" value="1" min="1" readonly>
     550                                <button class="quantity-btn" onclick="increaseQuickViewQuantity()">+</button>
     551                            </div>
     552                        </div>
     553
     554                        <button class="modal-add-to-cart" onclick="addQuickViewToCart(<?php echo esc_js($product_id); ?>)">
     555                            <i class="fas fa-shopping-cart"></i> <?php echo esc_html($product->single_add_to_cart_text()); ?>
     556                        </button>
     557
     558                        <!-- Meta Information -->
     559                        <div class="modal-meta">
     560                            <div><span><?php esc_html_e('SKU:', 'spiraclethemes-site-library'); ?></span> <span><?php echo esc_html( $product->get_sku() ? $product->get_sku() : esc_html__('N/A', 'spiraclethemes-site-library') ); ?></span></div>
     561                            <div><span><?php esc_html_e('Category:', 'spiraclethemes-site-library'); ?></span>
     562                                <?php
     563                                $categories = wp_get_post_terms( $product_id, 'product_cat' );
     564                                $category_names = array();
     565                                foreach ( $categories as $category ) {
     566                                    $category_names[] = esc_html( $category->name );
     567                                }
     568                                echo '<span>' . implode( ', ', $category_names ) . '</span>';
     569                                ?>
     570                            </div>
     571                        </div>
     572                    </div>
     573                </div>
     574            </div>
     575        </div>
     576        <?php
     577        $content = ob_get_clean();
     578
     579        wp_send_json_success( $content );
     580    }
     581    add_action( 'wp_ajax_own_shop_quick_view', 'spiraclethemes_site_library_own_shop_quick_view_ajax_handler' );
     582    add_action( 'wp_ajax_nopriv_own_shop_quick_view', 'spiraclethemes_site_library_own_shop_quick_view_ajax_handler' );
     583}
     584
     585/**
     586 * AJAX Handler for Quick View Add to Cart
     587 */
     588if( !function_exists('spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax') ) {
     589    function spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax() {
     590        check_ajax_referer( 'own_shop_quick_view_nonce', 'security' );
     591
     592        $product_id = intval( $_POST['product_id'] );
     593        $quantity = intval( $_POST['quantity'] );
     594        $variation_id = isset( $_POST['variation_id'] ) ? intval( $_POST['variation_id'] ) : 0;
     595        $variations = isset( $_POST['variation'] ) ? $_POST['variation'] : array();
     596
     597        if ( ! $product_id || $quantity < 1 ) {
     598            wp_send_json_error( __( 'Invalid product or quantity.', 'spiraclethemes-site-library' ) );
     599        }
     600
     601        $product = wc_get_product( $product_id );
     602
     603        if ( ! $product ) {
     604            wp_send_json_error( __( 'Product not found.', 'spiraclethemes-site-library' ) );
     605        }
     606
     607        // Handle variable products
     608        if ( $product->is_type( 'variable' ) ) {
     609            if ( ! $variation_id ) {
     610                wp_send_json_error( __( 'Please select product options.', 'spiraclethemes-site-library' ) );
     611            }
     612
     613            $variation = wc_get_product( $variation_id );
     614            if ( ! $variation || ! $variation->exists() || ! $variation->is_in_stock() ) {
     615                wp_send_json_error( __( 'Invalid variation selected.', 'spiraclethemes-site-library' ) );
     616            }
     617
     618            $product_id = $variation_id;
     619        }
     620
     621        // Check if product is in stock
     622        if ( ! $product->is_in_stock() ) {
     623            wp_send_json_error( __( 'Sorry, this product is out of stock.', 'spiraclethemes-site-library' ) );
     624        }
     625
     626        // Check stock quantity
     627        if ( ! $product->has_enough_stock( $quantity ) ) {
     628            wp_send_json_error( sprintf( __( 'Sorry, we do not have enough "%s" in stock to fulfill your order.', 'woocommerce' ), $product->get_name() ) );
     629        }
     630
     631        // Add to cart
     632        $cart_item_key = WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations );
     633
     634        if ( ! $cart_item_key ) {
     635            wp_send_json_error( __( 'Failed to add product to cart.', 'spiraclethemes-site-library' ) );
     636        }
     637
     638        // Return success response
     639        wp_send_json_success( array(
     640            'cart_hash' => WC()->cart->get_cart_hash(),
     641            'fragments' => apply_filters( 'woocommerce_add_to_cart_fragments', array() ),
     642            'cart_url' => wc_get_cart_url(),
     643            'message' => sprintf( __( '"%s" has been added to your cart.', 'woocommerce' ), $product->get_name() ),
     644        ) );
     645    }
     646    add_action( 'wp_ajax_own_shop_quick_view_add_to_cart', 'spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax' );
     647    add_action( 'wp_ajax_nopriv_own_shop_quick_view_add_to_cart', 'spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax' );
     648}
     649
     650/**
     651 * Add Quick View Button to Product Actions
     652 */
     653if( !function_exists('spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop') ) {
     654    function spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop() {
     655        add_action( 'woocommerce_after_shop_loop_item', 'spiraclethemes_site_library_own_shop_add_quick_view_button', 15 );
     656    }
     657    add_action( 'woocommerce_init', 'spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop' );
     658}
  • spiraclethemes-site-library/trunk/inc/own-store-functions.php

    r3327924 r3388695  
    8383                  'name'     => 'WooCommerce',
    8484                  'slug'     => 'woocommerce',
    85                   'required' => true,
    86                 ],
    87                 [
    88                   'name'     => 'YITH WooCommerce Quick View',
    89                   'slug'     => 'yith-woocommerce-quick-view',
    9085                  'required' => true,
    9186                ],
     
    442437    add_shortcode('recentblog', 'spiraclethemes_site_library_own_shop_recentblog');
    443438}
     439
     440
     441/**
     442 * Quick View Functions
     443 */
     444
     445/**
     446 * Add Quick View Button to WooCommerce Product Loop
     447 */
     448if( !function_exists('spiraclethemes_site_library_own_shop_add_quick_view_button') ) {
     449function spiraclethemes_site_library_own_shop_add_quick_view_button() {
     450    global $product;
     451    if ( $product && is_a( $product, 'WC_Product' ) ) {
     452        echo '<a href="#" class="own-shop-quick-view-btn" data-product-id="' . esc_attr( $product->get_id() ) . '" data-product-type="' . esc_attr( $product->get_type() ) . '" aria-label="' . esc_attr__( 'Quick View', 'spiraclethemes-site-library' ) . '"></a>';
     453    }
     454}
     455}
     456
     457/**
     458 * Enqueue Quick View Scripts
     459 */
     460if( !function_exists('spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts') ) {
     461    function spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts() {
     462        wp_enqueue_script( 'own-shop-quick-view', plugin_dir_url( __FILE__ ) . '../js/own-shop-quick-view.js', array( 'jquery' ), '1.0.0', true );
     463        wp_localize_script( 'own-shop-quick-view', 'own_shop_quick_view_ajax', array(
     464            'ajax_url' => admin_url( 'admin-ajax.php' ),
     465            'nonce' => wp_create_nonce( 'own_shop_quick_view_nonce' )
     466        ));
     467        // Enqueue parent quick view CSS
     468        wp_enqueue_style( 'own-shop-quick-view', plugin_dir_url( __FILE__ ) . '../css/own-shop-quick-view.css', array(), '1.0.0' );
     469        // Enqueue own-store specific CSS
     470        wp_enqueue_style( 'own-store-quick-view', plugin_dir_url( __FILE__ ) . '../css/own-store-quick-view.css', array('own-shop-quick-view'), '1.0.0' );
     471    }
     472    add_action( 'wp_enqueue_scripts', 'spiraclethemes_site_library_own_shop_enqueue_quick_view_scripts' );
     473}
     474
     475/**
     476 * AJAX Handler for Quick View
     477 */
     478if( !function_exists('spiraclethemes_site_library_own_shop_quick_view_ajax_handler') ) {
     479    function spiraclethemes_site_library_own_shop_quick_view_ajax_handler() {
     480        check_ajax_referer( 'own_shop_quick_view_nonce', 'nonce' );
     481
     482        $product_id = intval( $_POST['product_id'] );
     483        $product = wc_get_product( $product_id );
     484
     485        if ( !$product ) {
     486            wp_die( esc_html__( 'Product not found.', 'spiraclethemes-site-library' ) );
     487        }
     488
     489        ob_start();
     490        ?>
     491        <div class="own-shop-quick-view-modal">
     492            <div class="quick-view-content">
     493                <button class="quick-view-close" onclick="closeOwnShopQuickView()" aria-label="Close">
     494                    <i class="las la-times-circle"></i>
     495                </button>
     496                <div class="quick-view-body">
     497                    <div class="quick-view-images-section">
     498                        <?php
     499                        $attachment_ids = $product->get_gallery_image_ids();
     500                        $main_image_url = has_post_thumbnail( $product_id ) ? get_the_post_thumbnail_url( $product_id, 'large' ) : wc_placeholder_img_src();
     501                        ?>
     502                        <img id="quick-view-main-image" class="quick-view-main-image" src="<?php echo esc_url( $main_image_url ); ?>" alt="<?php echo esc_attr( $product->get_name() ); ?>">
     503
     504                        <?php if ( count( $attachment_ids ) > 1 || has_post_thumbnail( $product_id ) ) : ?>
     505                        <div class="quick-view-thumbnails">
     506                            <?php
     507                            if ( has_post_thumbnail( $product_id ) ) {
     508                                $thumbnail_url = get_the_post_thumbnail_url( $product_id, 'thumbnail' );
     509                                echo '<img class="thumbnail active" src="' . esc_url( $thumbnail_url ) . '" alt="Thumbnail" onclick="changeQuickViewImage(\'' . esc_js( $thumbnail_url ) . '\', this)">';
     510                            }
     511                            if ( $attachment_ids ) {
     512                                foreach ( $attachment_ids as $attachment_id ) {
     513                                    $thumbnail_url = wp_get_attachment_image_url( $attachment_id, 'thumbnail' );
     514                                    $large_url = wp_get_attachment_image_url( $attachment_id, 'large' );
     515                                    echo '<img class="thumbnail" src="' . esc_url( $thumbnail_url ) . '" alt="Thumbnail" onclick="changeQuickViewImage(\'' . esc_js( $large_url ) . '\', this)">';
     516                                }
     517                            }
     518                            ?>
     519                        </div>
     520                        <?php endif; ?>
     521                    </div>
     522                    <div class="quick-view-details">
     523                        <h2 class="quick-view-title"><?php echo esc_html( $product->get_name() ); ?></h2>
     524
     525                        <div class="quick-view-rating">
     526                            <?php
     527                            $rating_count = $product->get_rating_count();
     528                            $review_count = $product->get_review_count();
     529                            $average = $product->get_average_rating();
     530                            ?>
     531                            <?php echo wc_get_rating_html( $average, $rating_count ); ?>
     532                            <?php if ( comments_open() && $review_count ) : ?>
     533                                <span class="modal-reviews"><?php printf( _n( '(%s review)', '(%s reviews)', $review_count, 'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?></span>
     534                            <?php endif ?>
     535                        </div>
     536
     537                        <div class="quick-view-price"><?php echo $product->get_price_html(); ?></div>
     538
     539                        <div class="quick-view-description">
     540                            <?php echo wp_kses_post( $product->get_short_description() ? $product->get_short_description() : $product->get_description() ); ?>
     541                        </div>
     542
     543                        <!-- Stock Status -->
     544                        <div class="modal-stock"><?php echo esc_html( $product->is_in_stock() ? 'In Stock' : 'Out of Stock' ); ?></div>
     545
     546                        <div class="quick-view-quantity">
     547                            <span class="quantity-label"><?php esc_html_e('Quantity:', 'woocommerce'); ?></span>
     548                            <div class="quantity-input">
     549                                <button class="quantity-btn" onclick="decreaseQuickViewQuantity()">-</button>
     550                                <input type="number" class="quantity-value" id="quick-view-quantity" value="1" min="1" readonly>
     551                                <button class="quantity-btn" onclick="increaseQuickViewQuantity()">+</button>
     552                            </div>
     553                        </div>
     554
     555                        <button class="modal-add-to-cart" onclick="addQuickViewToCart(<?php echo esc_js($product_id); ?>)">
     556                            <i class="fas fa-shopping-cart"></i> <?php echo esc_html($product->single_add_to_cart_text()); ?>
     557                        </button>
     558
     559                        <!-- Meta Information -->
     560                        <div class="modal-meta">
     561                            <div><span><?php esc_html_e('SKU:', 'spiraclethemes-site-library'); ?></span> <span><?php echo esc_html( $product->get_sku() ? $product->get_sku() : esc_html__('N/A', 'spiraclethemes-site-library') ); ?></span></div>
     562                            <div><span><?php esc_html_e('Category:', 'spiraclethemes-site-library'); ?></span>
     563                                <?php
     564                                $categories = wp_get_post_terms( $product_id, 'product_cat' );
     565                                $category_names = array();
     566                                foreach ( $categories as $category ) {
     567                                    $category_names[] = esc_html( $category->name );
     568                                }
     569                                echo '<span>' . implode( ', ', $category_names ) . '</span>';
     570                                ?>
     571                            </div>
     572                        </div>
     573                    </div>
     574                </div>
     575            </div>
     576        </div>
     577        <?php
     578        $content = ob_get_clean();
     579
     580        wp_send_json_success( $content );
     581    }
     582    add_action( 'wp_ajax_own_shop_quick_view', 'spiraclethemes_site_library_own_shop_quick_view_ajax_handler' );
     583    add_action( 'wp_ajax_nopriv_own_shop_quick_view', 'spiraclethemes_site_library_own_shop_quick_view_ajax_handler' );
     584}
     585
     586/**
     587 * AJAX Handler for Quick View Add to Cart
     588 */
     589if( !function_exists('spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax') ) {
     590    function spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax() {
     591        check_ajax_referer( 'own_shop_quick_view_nonce', 'security' );
     592
     593        $product_id = intval( $_POST['product_id'] );
     594        $quantity = intval( $_POST['quantity'] );
     595        $variation_id = isset( $_POST['variation_id'] ) ? intval( $_POST['variation_id'] ) : 0;
     596        $variations = isset( $_POST['variation'] ) ? $_POST['variation'] : array();
     597
     598        if ( ! $product_id || $quantity < 1 ) {
     599            wp_send_json_error( __( 'Invalid product or quantity.', 'spiraclethemes-site-library' ) );
     600        }
     601
     602        $product = wc_get_product( $product_id );
     603
     604        if ( ! $product ) {
     605            wp_send_json_error( __( 'Product not found.', 'spiraclethemes-site-library' ) );
     606        }
     607
     608        // Handle variable products
     609        if ( $product->is_type( 'variable' ) ) {
     610            if ( ! $variation_id ) {
     611                wp_send_json_error( __( 'Please select product options.', 'spiraclethemes-site-library' ) );
     612            }
     613
     614            $variation = wc_get_product( $variation_id );
     615            if ( ! $variation || ! $variation->exists() || ! $variation->is_in_stock() ) {
     616                wp_send_json_error( __( 'Invalid variation selected.', 'spiraclethemes-site-library' ) );
     617            }
     618
     619            $product_id = $variation_id;
     620        }
     621
     622        // Check if product is in stock
     623        if ( ! $product->is_in_stock() ) {
     624            wp_send_json_error( __( 'Sorry, this product is out of stock.', 'spiraclethemes-site-library' ) );
     625        }
     626
     627        // Check stock quantity
     628        if ( ! $product->has_enough_stock( $quantity ) ) {
     629            wp_send_json_error( sprintf( __( 'Sorry, we do not have enough "%s" in stock to fulfill your order.', 'woocommerce' ), $product->get_name() ) );
     630        }
     631
     632        // Add to cart
     633        $cart_item_key = WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations );
     634
     635        if ( ! $cart_item_key ) {
     636            wp_send_json_error( __( 'Failed to add product to cart.', 'spiraclethemes-site-library' ) );
     637        }
     638
     639        // Return success response
     640        wp_send_json_success( array(
     641            'cart_hash' => WC()->cart->get_cart_hash(),
     642            'fragments' => apply_filters( 'woocommerce_add_to_cart_fragments', array() ),
     643            'cart_url' => wc_get_cart_url(),
     644            'message' => sprintf( __( '"%s" has been added to your cart.', 'woocommerce' ), $product->get_name() ),
     645        ) );
     646    }
     647    add_action( 'wp_ajax_own_shop_quick_view_add_to_cart', 'spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax' );
     648    add_action( 'wp_ajax_nopriv_own_shop_quick_view_add_to_cart', 'spiraclethemes_site_library_own_shop_quick_view_add_to_cart_ajax' );
     649}
     650
     651/**
     652 * Add Quick View Button to Product Actions
     653 */
     654if( !function_exists('spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop') ) {
     655    function spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop() {
     656        add_action( 'woocommerce_after_shop_loop_item', 'spiraclethemes_site_library_own_shop_add_quick_view_button', 15 );
     657    }
     658    add_action( 'woocommerce_init', 'spiraclethemes_site_library_own_shop_add_quick_view_to_product_loop' );
     659}
  • spiraclethemes-site-library/trunk/spiraclethemes-site-library.php

    r3360556 r3388695  
    44 * Plugin URI:        https://wordpress.org/plugins/spiraclethemes-site-library/
    55 * Description:       A plugin by Spiracle Themes that adds one-click demo import, theme customization, starter templates, and page builder support to its free themes.
    6  * Version:           1.5.7
     6 * Version:           1.5.8
    77 * Author:            SpiracleThemes
    88 * Author URI:        https://spiraclethemes.com
     
    5353        delete_user_meta( $user_id, 'spiraclethemes_sitelib_rating_ignore_notice' );
    5454        delete_user_meta( $user_id, 'spiraclethemes_sitelib_training_ignore_notice' );
    55         // Clean up new $3/month plan notice meta keys
    56         delete_user_meta( $user_id, 'spiraclethemes_sitelib_3dollar_0day_notice' );
    57         delete_user_meta( $user_id, 'spiraclethemes_sitelib_3dollar_7day_notice' );
    58         delete_user_meta( $user_id, 'spiraclethemes_sitelib_3dollar_14day_notice' );
    59         delete_user_meta( $user_id, 'spiraclethemes_sitelib_3dollar_28day_notice' );
    60         delete_user_meta( $user_id, 'spiraclethemes_sitelib_3dollar_60day_notice' );
     55        // Clean up plan notice meta keys
     56        delete_user_meta( $user_id, 'spiraclethemes_sitelib_49dollar_0day_notice' );
     57        delete_user_meta( $user_id, 'spiraclethemes_sitelib_49dollar_7day_notice' );
     58        delete_user_meta( $user_id, 'spiraclethemes_sitelib_49dollar_14day_notice' );
     59        delete_user_meta( $user_id, 'spiraclethemes_sitelib_49dollar_28day_notice' );
     60        delete_user_meta( $user_id, 'spiraclethemes_sitelib_49dollar_60day_notice' );
    6161    }
    6262
     
    101101            add_action( 'admin_init', [ $this, 'spiraclethemes_site_library_set_notification' ] );
    102102            add_action( 'admin_notices', [ $this, 'spiraclethemes_site_library_display_welcome_notice' ] );
    103             add_action( 'admin_notices', [ $this, 'spiraclethemes_site_library_display_3dollar_notices' ] );
     103            add_action( 'admin_notices', [ $this, 'spiraclethemes_site_library_display_49dollar_notices' ] );
    104104            add_action( 'admin_init', [ $this, 'spiraclethemes_site_library_ignore_rating_notice' ] );
    105             add_action( 'admin_init', [ $this, 'spiraclethemes_site_library_ignore_3dollar_notices' ] );
     105            add_action( 'admin_init', [ $this, 'spiraclethemes_site_library_ignore_49dollar_notices' ] );
    106106        }
    107107        add_action('init', [ $this, 'spiraclethemes_site_library_load_plugin_textdomain' ] );
     
    193193    }
    194194
    195     // Reusable method to build $3/month plan notice message
    196     private function spiraclethemes_site_library_build_3dollar_notice( $days, $ignore_param, $theme_name ) {
    197         $pricing_url = esc_url( 'https://spiraclethemes.com/pricing/' );
    198        
     195    // Get theme-specific pricing URL
     196    private function spiraclethemes_site_library_get_theme_pricing_url() {
     197        $theme_pricing_urls = [
     198            'own-shop' => 'https://spiraclethemes.com/own-shop-pro-addons/',
     199            'purea-magazine' => 'https://spiraclethemes.com/purea-magazine-pro-addons',
     200            'colon' => 'https://spiraclethemes.com/colon-pro-addons/',
     201            'somalite' => 'https://spiraclethemes.com/soma-pro-addons/',
     202            'purea-fashion' => 'https://spiraclethemes.com/purea-magazine-pro-addons/',
     203            'own-store' => 'https://spiraclethemes.com/own-shop-pro-addons/',
     204            'colon-plus' => 'https://spiraclethemes.com/colon-pro-addons/',
     205            'own-shop-lite' => 'https://spiraclethemes.com/own-shop-lite-pro-addons/',
     206            'mestore' => 'https://spiraclethemes.com/mestore-pro-addons',
     207            'blogson' => 'https://spiraclethemes.com/blogson-pro-addons/',
     208            'blogson-child' => 'https://spiraclethemes.com/blogson-pro-addons/',
     209            'own-shope' => 'https://spiraclethemes.com/own-shope-free-wordpress-theme/#pricing',
     210            'crater-free' => 'https://spiraclethemes.com/crater-pro-addons/',
     211            'lawfiz' => 'https://spiraclethemes.com/lawfiz-theme/#pricing',
     212            'legalblow' => 'https://spiraclethemes.com/legalblow-theme/#pricing',
     213            'own-shop-trend' => 'https://spiraclethemes.com/own-shop-pro-addons/',
     214            'lawfiz-one' => 'https://spiraclethemes.com/lawfiz-one-theme/#pricing',
     215            'krystal' => 'https://spiraclethemes.com/krystal-pro-addons/',
     216            'krystal-lawyer' => 'https://spiraclethemes.com/krystal-pro-addons/',
     217            'krystal-business' => 'https://spiraclethemes.com/krystal-pro-addons/',
     218            'krystal-shop' => 'https://spiraclethemes.com/krystal-pro-addons/'
     219        ];
     220
     221        return isset($theme_pricing_urls[$this->theme_slug]) ? esc_url($theme_pricing_urls[$this->theme_slug]) : esc_url('https://spiraclethemes.com/pricing/');
     222    }
     223
     224    // Reusable method to build $49/year plan notice message
     225    private function spiraclethemes_site_library_build_49dollar_notice( $days, $ignore_param, $theme_name ) {
     226        $pricing_url = $this->spiraclethemes_site_library_get_theme_pricing_url();
     227
    199228        // Convert theme name to title case and append "Pro"
    200229        $theme_pro_name = ucwords( $theme_name ) . ' Pro';
    201        
     230
    202231        // For all notices, use "Remind me later" option
    203232        $ignore_url = esc_url( wp_nonce_url( admin_url( 'themes.php?' . $ignore_param . '=0' ), $ignore_param . '_nonce' ) );
    204         $message = __( '🎉 Special Offer! %3$s now at just <span style="background: #319942; padding: 4px 8px; border-radius: 25px; color: #fff;"><strong>$3/month</strong></span> <del>$5/month</del> – making Pro accessible to all! Visit <a href="%1$s" target="_blank">our pricing page</a> to learn more. <a href="%2$s">Remind me later</a>', 'spiraclethemes-site-library' );
     233        $message = __( '🎉 Special Offer! %3$s now at just <span style="background: #319942; padding: 4px 8px; border-radius: 25px; color: #fff;"><strong>$49</strong></span> <del>$59</del> – making Pro accessible to all! Visit <a href="%1$s" target="_blank">our pricing page</a> to learn more. <a href="%2$s">Remind me later</a>', 'spiraclethemes-site-library' );
    205234        return sprintf( wp_kses_post( $message ), $pricing_url, $ignore_url, $theme_pro_name );
    206235    }
     
    221250        }
    222251       
    223         // Show rating notice after 7 days, but only if $3/month notices haven't been shown
     252        // Show rating notice after 7 days, but only if $49/year notices haven't been shown
    224253        $should_show_rating = true;
    225254        $notice_schedule = [
    226             ['days' => 0, 'key' => 'spiraclethemes_sitelib_3dollar_0day_notice'],
    227             ['days' => 7, 'key' => 'spiraclethemes_sitelib_3dollar_7day_notice'],
    228             ['days' => 14, 'key' => 'spiraclethemes_sitelib_3dollar_14day_notice'],
    229             ['days' => 28, 'key' => 'spiraclethemes_sitelib_3dollar_28day_notice'],
    230             ['days' => 60, 'key' => 'spiraclethemes_sitelib_3dollar_60day_notice']
     255            ['days' => 0, 'key' => 'spiraclethemes_sitelib_49dollar_0day_notice'],
     256            ['days' => 7, 'key' => 'spiraclethemes_sitelib_49dollar_7day_notice'],
     257            ['days' => 14, 'key' => 'spiraclethemes_sitelib_49dollar_14day_notice'],
     258            ['days' => 28, 'key' => 'spiraclethemes_sitelib_49dollar_28day_notice'],
     259            ['days' => 60, 'key' => 'spiraclethemes_sitelib_49dollar_60day_notice']
    231260        ];
    232        
    233         // Check if any $3/month notices have been shown or should be shown
     261
     262        // Check if any $49/year notices have been shown or should be shown
    234263        foreach ($notice_schedule as $notice) {
    235264            if ($days_since >= $notice['days']) {
     
    241270            }
    242271        }
    243        
    244         // Show rating notice after 7 days if no $3/month notices have been shown
     272
     273        // Show rating notice after 7 days if no $49/year notices have been shown
    245274        if ( $should_show_rating && $days_since >= 7 && $this->spiraclethemes_site_library_should_display_notice( 'spiraclethemes_sitelib_rating_ignore_notice', 7 ) ) {
    246275            $theme_info_url = esc_url( admin_url( 'themes.php' ) );
     
    263292
    264293
    265     // Reusable method to check if $3/month plan notice should be shown
    266     private function spiraclethemes_site_library_should_display_3dollar_notice( $ignore_key, $days_after_install, $is_permanent = false ) {
     294    // Reusable method to check if $49/year plan notice should be shown
     295    private function spiraclethemes_site_library_should_display_49dollar_notice( $ignore_key, $days_after_install, $is_permanent = false ) {
    267296        $install_date = get_option( 'spiraclethemes_sitelib_install_date' );
    268297        if ( strtotime( "+$days_after_install days", strtotime( $install_date ) ) > time() ) {
     
    272301        $user_id = get_current_user_id();
    273302        $dismissal_data = get_user_meta( $user_id, $ignore_key, true );
    274        
     303
    275304        // If no dismissal data, show the notice
    276305        if ( empty( $dismissal_data ) ) {
    277306            return true;
    278307        }
    279        
     308
    280309        // If permanent dismissal, never show again
    281310        if ( $is_permanent ) {
    282311            return false;
    283312        }
    284        
     313
    285314        // For temporary dismissal, check if it's time to remind again
    286315        $reminder_time = intval( $dismissal_data );
     
    288317    }
    289318
    290     // $3/month plan notices - single function to determine which notice to show
    291     public function spiraclethemes_site_library_display_3dollar_notices() {
     319    // $49/year plan notices - single function to determine which notice to show
     320    public function spiraclethemes_site_library_display_49dollar_notices() {
    292321        $days_since = $this->spiraclethemes_site_library_get_days_since_install();
    293322        $user_id = get_current_user_id();
    294        
     323
    295324        // Define notice schedule
    296325        $notice_schedule = [
    297             ['days' => 0, 'key' => 'spiraclethemes_sitelib_3dollar_0day_notice'],
    298             ['days' => 7, 'key' => 'spiraclethemes_sitelib_3dollar_7day_notice'],
    299             ['days' => 14, 'key' => 'spiraclethemes_sitelib_3dollar_14day_notice'],
    300             ['days' => 28, 'key' => 'spiraclethemes_sitelib_3dollar_28day_notice'],
    301             ['days' => 60, 'key' => 'spiraclethemes_sitelib_3dollar_60day_notice']
     326            ['days' => 0, 'key' => 'spiraclethemes_sitelib_49dollar_0day_notice'],
     327            ['days' => 7, 'key' => 'spiraclethemes_sitelib_49dollar_7day_notice'],
     328            ['days' => 14, 'key' => 'spiraclethemes_sitelib_49dollar_14day_notice'],
     329            ['days' => 28, 'key' => 'spiraclethemes_sitelib_49dollar_28day_notice'],
     330            ['days' => 60, 'key' => 'spiraclethemes_sitelib_49dollar_60day_notice']
    302331        ];
    303332       
     
    333362        // Show the appropriate notice
    334363        if ($notice_to_show) {
    335             $message = $this->spiraclethemes_site_library_build_3dollar_notice(
     364            $message = $this->spiraclethemes_site_library_build_49dollar_notice(
    336365                $notice_to_show['days'],
    337                 'wp_spiraclethemes_sitelib_3dollar_ignore',
     366                'wp_spiraclethemes_sitelib_49dollar_ignore',
    338367                $this->theme_name
    339368            );
     
    343372
    344373
    345     // Public ignore handlers for $3/month plan notices
    346     public function spiraclethemes_site_library_ignore_3dollar_notices() {
    347         if ( current_user_can( 'manage_options' ) && isset( $_GET['wp_spiraclethemes_sitelib_3dollar_ignore'] ) && isset( $_GET['_wpnonce'] ) ) {
    348             if ( wp_verify_nonce( sanitize_text_field($_GET['_wpnonce']), 'wp_spiraclethemes_sitelib_3dollar_ignore_nonce' ) ) {
     374    // Public ignore handlers for $49/year plan notices
     375    public function spiraclethemes_site_library_ignore_49dollar_notices() {
     376        if ( current_user_can( 'manage_options' ) && isset( $_GET['wp_spiraclethemes_sitelib_49dollar_ignore'] ) && isset( $_GET['_wpnonce'] ) ) {
     377            if ( wp_verify_nonce( sanitize_text_field($_GET['_wpnonce']), 'wp_spiraclethemes_sitelib_49dollar_ignore_nonce' ) ) {
    349378                $user_id = get_current_user_id();
    350379                $days_since = $this->spiraclethemes_site_library_get_days_since_install();
    351                
     380
    352381                // Define notice schedule
    353382                $notice_schedule = [
    354                     ['days' => 0, 'key' => 'spiraclethemes_sitelib_3dollar_0day_notice'],
    355                     ['days' => 7, 'key' => 'spiraclethemes_sitelib_3dollar_7day_notice'],
    356                     ['days' => 14, 'key' => 'spiraclethemes_sitelib_3dollar_14day_notice'],
    357                     ['days' => 28, 'key' => 'spiraclethemes_sitelib_3dollar_28day_notice'],
    358                     ['days' => 60, 'key' => 'spiraclethemes_sitelib_3dollar_60day_notice']
     383                    ['days' => 0, 'key' => 'spiraclethemes_sitelib_49dollar_0day_notice'],
     384                    ['days' => 7, 'key' => 'spiraclethemes_sitelib_49dollar_7day_notice'],
     385                    ['days' => 14, 'key' => 'spiraclethemes_sitelib_49dollar_14day_notice'],
     386                    ['days' => 28, 'key' => 'spiraclethemes_sitelib_49dollar_28day_notice'],
     387                    ['days' => 60, 'key' => 'spiraclethemes_sitelib_49dollar_60day_notice']
    359388                ];
    360389               
Note: See TracChangeset for help on using the changeset viewer.