Support » Plugin: Woocommerce Upsell Popup » Show Popup on Custom Pages

  • Plugin Author 10Horizons

    (@tentenbiz)


    If you don’t have the PRO version, this is how to get the popup to work on custom pages (non-Woocommerce pages).

    Copy and paste the following code to your child theme’s functions.php file:

    function wup_upsell_popup_scripts_enqueue () {
    	
    	if (( is_page( 13 ) ) && (! thp_wuppro_active() )) { //CHANGE 13 TO THE ID OF YOUR PAGE!
    		
    		$ajax_enabled = get_option( 'woocommerce_enable_ajax_add_to_cart' );
    		
    		if ( 'yes' === $ajax_enabled ) {
    			wp_enqueue_script( 'thp-popup-js', get_site_url().'/wp-content/plugins/very-simple-woocommerce-upsell-popup/js/wup-ajax.min.js', array('jquery'), '', false );
    			wp_localize_script( 'thp-popup-js', 'thp_popup_vars', array(
    				'ajaxurl' => admin_url( 'admin-ajax.php' ),
    				'added_to_cart' => __( 'Added to Cart!', 'very-simple-woocommerce-upsell-popup' )
    				)
    			);
    			wp_enqueue_script( 'wup-noajax-js', get_site_url().'/wp-content/plugins/very-simple-woocommerce-upsell-popup/js/wup-noajax.min.js', array('jquery'), '', false );
    		}
    		elseif ( 'yes' != $ajax_enabled ) {
    			wp_enqueue_script( 'wup-noajax-js', get_site_url().'/wp-content/plugins/very-simple-woocommerce-upsell-popup/js/wup-noajax.min.js', array('jquery'), '', false );
    		}
    		
    	}
    }
    add_action( 'wp_enqueue_scripts', 'wup_upsell_popup_scripts_enqueue' );

    Don’t forget to change the ID in the code above (line 3) to the actual ID of your page!

    If you have the PRO version, refer to this documentation instead: https://woocommerce.upsellpopup.com/docs/woocommerce-upsell-popup-pro-docs/troubleshooting/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author 10Horizons

    (@tentenbiz)

    Here is the LATEST, revised code. Same as above, but with new localization strings added.

    function wup_upsell_popup_scripts_enqueue () {
    	
    	if (( is_page( 13 ) ) && (! thp_wuppro_active() )) { //CHANGE 13 TO THE ID OF YOUR PAGE!
    		
    		$ajax_enabled = get_option( 'woocommerce_enable_ajax_add_to_cart' );
    		
    		if ( 'yes' === $ajax_enabled ) {
    			wp_enqueue_script( 'thp-popup-js', get_site_url().'/wp-content/plugins/very-simple-woocommerce-upsell-popup/js/wup-ajax.min.js', array('jquery'), '', false );
    			wp_localize_script( 'thp-popup-js', 'thp_popup_vars', array(
    				'ajaxurl' => admin_url( 'admin-ajax.php' ),
    				'added_to_cart' => __( 'Added to Cart!', 'very-simple-woocommerce-upsell-popup' ),
    				'choose_one' => __( 'Please choose one option!', 'very-simple-woocommerce-upsell-popup' )
    				)
    			);
    			wp_enqueue_script( 'wup-noajax-js', get_site_url().'/wp-content/plugins/very-simple-woocommerce-upsell-popup/js/wup-noajax.min.js', array('jquery'), '', false );
    		}
    		elseif ( 'yes' != $ajax_enabled ) {
    			wp_enqueue_script( 'wup-noajax-js', get_site_url().'/wp-content/plugins/very-simple-woocommerce-upsell-popup/js/wup-noajax.min.js', array('jquery'), '', false );
    			wp_localize_script( 'wup-noajax-js', 'wup_noajax_js_vars', array(
    				'choose_one' => __( 'Please choose one option!', 'very-simple-woocommerce-upsell-popup' )
    				)
    			);
    		}
    		
    	}
    }
    Plugin Author 10Horizons

    (@tentenbiz)

    Sorry, forgot the add_action line that should be at the end of the code above.

    The full code should be:

    function wup_upsell_popup_scripts_enqueue () {
    	
    	if (( is_page( 13 ) ) && (! thp_wuppro_active() )) { //CHANGE 13 TO THE ID OF YOUR PAGE!
    		
    		$ajax_enabled = get_option( 'woocommerce_enable_ajax_add_to_cart' );
    		
    		if ( 'yes' === $ajax_enabled ) {
    			wp_enqueue_script( 'thp-popup-js', get_site_url().'/wp-content/plugins/very-simple-woocommerce-upsell-popup/js/wup-ajax.min.js', array('jquery'), '', false );
    			wp_localize_script( 'thp-popup-js', 'thp_popup_vars', array(
    				'ajaxurl' => admin_url( 'admin-ajax.php' ),
    				'added_to_cart' => __( 'Added to Cart!', 'very-simple-woocommerce-upsell-popup' ),
    				'choose_one' => __( 'Please choose one option!', 'very-simple-woocommerce-upsell-popup' )
    				)
    			);
    			wp_enqueue_script( 'wup-noajax-js', get_site_url().'/wp-content/plugins/very-simple-woocommerce-upsell-popup/js/wup-noajax.min.js', array('jquery'), '', false );
    		}
    		elseif ( 'yes' != $ajax_enabled ) {
    			wp_enqueue_script( 'wup-noajax-js', get_site_url().'/wp-content/plugins/very-simple-woocommerce-upsell-popup/js/wup-noajax.min.js', array('jquery'), '', false );
    			wp_localize_script( 'wup-noajax-js', 'wup_noajax_js_vars', array(
    				'choose_one' => __( 'Please choose one option!', 'very-simple-woocommerce-upsell-popup' )
    				)
    			);
    		}
    		
    	}
    }
    add_action( 'wp_enqueue_scripts', 'wup_upsell_popup_scripts_enqueue' );

    Sorry for the confusion.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.