| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Settings; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
/** |
| 7 |
* Sellkit settings. |
| 8 |
* |
| 9 |
* @since 1.1.0 |
| 10 |
*/ |
| 11 |
class Sellkit_Settings { |
| 12 |
/** |
| 13 |
* The class instance. |
| 14 |
* |
| 15 |
* @var Object Class instance. |
| 16 |
* @since 1.1.0 |
| 17 |
*/ |
| 18 |
public static $instance = null; |
| 19 |
|
| 20 |
/** |
| 21 |
* Class Instance. |
| 22 |
* |
| 23 |
* @since 1.1.0 |
| 24 |
* @return Sellkit_Settings|null |
| 25 |
*/ |
| 26 |
public static function get_instance() { |
| 27 |
if ( null === self::$instance ) { |
| 28 |
self::$instance = new self(); |
| 29 |
} |
| 30 |
|
| 31 |
return self::$instance; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Class construct. |
| 36 |
* |
| 37 |
* @since 1.1.0 |
| 38 |
*/ |
| 39 |
public function __construct() { |
| 40 |
add_action( 'wp', [ $this, 'apply_sellkit_cart_settings' ] ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Apply sellkit cart settings in frontend. |
| 45 |
* |
| 46 |
* @since 1.1.0 |
| 47 |
* @return void |
| 48 |
*/ |
| 49 |
public function apply_sellkit_cart_settings() { |
| 50 |
$options = get_option( 'sellkit', [] ); |
| 51 |
|
| 52 |
if ( is_admin() || ! function_exists( 'WC' ) || ! is_cart() ) { |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
// Escape default woocommerce cart page. |
| 57 |
if ( array_key_exists( 'skip_cart_page', $options ) && '1' === $options['skip_cart_page'] ) { |
| 58 |
if ( WC()->cart->cart_contents_count > 0 ) { |
| 59 |
echo wc_get_checkout_url(); |
| 60 |
wp_safe_redirect( wc_get_checkout_url() ); |
| 61 |
exit(); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
// Set default woocommerce empty cart page template. |
| 66 |
if ( |
| 67 |
empty( $options['empty_cart_template'] ) |
| 68 |
|| empty( $options['empty_cart_template'][0] ) |
| 69 |
|| ! defined( 'ELEMENTOR_VERSION' ) |
| 70 |
|| WC()->cart->cart_contents_count > 0 |
| 71 |
) { |
| 72 |
return; |
| 73 |
} |
| 74 |
|
| 75 |
$template_id = $options['empty_cart_template'][0]; |
| 76 |
|
| 77 |
if ( (int) $template_id <= 0 ) { |
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
add_action( 'template_redirect', function() { |
| 82 |
jupiterx_add_filter( 'jupiterx_layout', 'c' ); |
| 83 |
|
| 84 |
sellkit()->load_files( [ |
| 85 |
'templates/canvas', |
| 86 |
] ); |
| 87 |
|
| 88 |
exit; |
| 89 |
}, 5 ); |
| 90 |
|
| 91 |
add_filter( 'the_content', function() use ( $template_id ) { |
| 92 |
ob_start(); |
| 93 |
echo \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $template_id, true ); |
| 94 |
return ob_get_clean(); |
| 95 |
} ); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
Sellkit_Settings::get_instance(); |
| 100 |
|