refactor(Core): optimize admin panel and refactor
This commit is contained in:
@@ -11,7 +11,8 @@ global $sodino_banner_service;
|
||||
$bannerRepository = new BannerRepository();
|
||||
$sodino_banner_service = new BannerService($bannerRepository);
|
||||
|
||||
add_action('wp_head', 'sodino_render_top_banner', 1);
|
||||
add_action('wp_body_open', 'sodino_render_top_banner', 5);
|
||||
add_action('wp_footer', 'sodino_render_top_banner_fallback', 5);
|
||||
add_filter('the_content', 'sodino_render_middle_banner');
|
||||
add_action('wp_footer', 'sodino_render_bottom_banner', 20);
|
||||
add_action('woocommerce_after_single_product_summary', 'sodino_render_product_banner', 5);
|
||||
@@ -101,13 +102,28 @@ function sodino_render_banner_position($position) {
|
||||
}
|
||||
|
||||
function sodino_render_top_banner() {
|
||||
static $rendered = false;
|
||||
|
||||
if (is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($rendered) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rendered = true;
|
||||
echo sodino_render_banner_position('top');
|
||||
}
|
||||
|
||||
function sodino_render_top_banner_fallback() {
|
||||
if (did_action('wp_body_open')) {
|
||||
return;
|
||||
}
|
||||
|
||||
sodino_render_top_banner();
|
||||
}
|
||||
|
||||
function sodino_render_middle_banner($content) {
|
||||
if (is_admin() || !is_singular() || !in_the_loop() || is_feed()) {
|
||||
return $content;
|
||||
@@ -146,7 +162,8 @@ function sodino_render_cart_banner() {
|
||||
}
|
||||
|
||||
function sodino_handle_banner_click() {
|
||||
if (!isset($_POST['banner_id']) || !isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'sodino_banner_click')) {
|
||||
$nonce = $_POST['nonce'] ?? ($_POST['security'] ?? '');
|
||||
if (!isset($_POST['banner_id']) || !wp_verify_nonce($nonce, 'sodino_banner_click')) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,17 +22,7 @@ add_filter('woocommerce_product_get_sale_price', 'sodino_apply_dynamic_pricing',
|
||||
add_filter('woocommerce_product_variation_get_price', 'sodino_apply_dynamic_pricing', 10, 2);
|
||||
add_filter('woocommerce_product_variation_get_sale_price', 'sodino_apply_dynamic_pricing', 10, 2);
|
||||
|
||||
// Also hook into cart and checkout prices
|
||||
add_filter('woocommerce_cart_item_price', 'sodino_apply_to_cart_item', 10, 3);
|
||||
add_filter('woocommerce_cart_item_subtotal', 'sodino_apply_to_cart_item', 10, 3);
|
||||
|
||||
function sodino_apply_dynamic_pricing($price, $product) {
|
||||
global $sodino_pricing_service;
|
||||
return $sodino_pricing_service->applyDynamicPricing($price, $product);
|
||||
}
|
||||
|
||||
function sodino_apply_to_cart_item($price, $cart_item, $cart_item_key) {
|
||||
global $sodino_pricing_service;
|
||||
$product = $cart_item['data'];
|
||||
return wc_price($sodino_pricing_service->applyDynamicPricing($product->get_price(), $product));
|
||||
}
|
||||
Reference in New Issue
Block a user