Upsell shortcode

0.0/5
<?php
add_shortcode('upsell_peeler', function () {
			
		
			$product_id = apply_filters( 'wpml_object_id', 2862, 'product' );
  
   			$product_cart_id = WC()->cart->generate_cart_id( $product_id );
   			$in_cart = WC()->cart->find_product_in_cart( $product_cart_id );
			if ( $in_cart ) {
				if (is_cart()) {
					add_action( 'wp_footer', 'trigger_myscript', 10, 5);
				}
				add_filter( 'woocommerce_get_price_html', 'bbloomer_alter_price_display', 9999, 2 );
				echo '<div class="upsell-popup">';
				echo '<h3 style="text-align:center; font-size: 40px; font-weight: bold;">' . sprintf( esc_html__( '%s discount', 'woocommerce' ), '50%', '' ) . '</h3>';
				echo do_shortcode('
'); echo '</div>'; } else { ?> <style> #cart-sale { display: none; } #cart-sale-long { width: 100%; } </style> <?php return; } }); function trigger_myscript() { ?> <script type="text/javascript"> jQuery( window ).on( 'load', function() { elementorProFrontend.modules.popup.showPopup( { id: 23734 } ); }); </script> <?php } function bbloomer_alter_price_display( $price_html, $product ) { if ( is_admin() ) return $price_html; if ( '' === $product->get_price() ) return $price_html; if ( apply_filters( 'wpml_object_id', $product->get_id(), 'product' ) == apply_filters( 'wpml_object_id', 3621, 'product' ) ) { $orig_price = $product->get_regular_price(); //$orig_price = wc_get_price_to_display( $product ); echo '<del style="font-size: 18px;">' . $orig_price . " " . get_woocommerce_currency_symbol() . '</del>'; $price_html = wc_price( $orig_price * 0.50 ); //$price_html = wc_price( $orig_price ); } return $price_html; } add_action( 'woocommerce_before_calculate_totals', 'bbloomer_alter_price_cart', 9999 ); function bbloomer_alter_price_cart( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $product_id = apply_filters( 'wpml_object_id', 2862, 'product' ); $product_cart_id = WC()->cart->generate_cart_id( $product_id ); $in_cart = WC()->cart->find_product_in_cart( $product_cart_id ); if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 ) return; if ( $in_cart ) { foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) { if ( apply_filters( 'wpml_object_id', $cart_item['product_id'], 'product' ) == apply_filters( 'wpml_object_id', 3621, 'product' ) ) { $product = $cart_item['data']; $price = $product->get_regular_price(); $cart_item['data']->set_price( $price * 0.50 ); //$cart_item['data']->set_price( $price ); } } } }

Comments and reviews

{{ reviewsTotal }} Review
{{ reviewsTotal }} Reviews
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}

Description

This snippet was fetched automatically from WPDistro.cz projects.

Author

Tags

This snippet is untagged