| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main ActionHooks class. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Controllers\Hooks; |
| 9 |
|
| 10 |
use RadiusTheme\SB\Helpers\Fns; |
| 11 |
use RadiusTheme\SB\Helpers\Cache; |
| 12 |
use RadiusTheme\SB\Models\GeneralList; |
| 13 |
use RadiusTheme\SB\Helpers\BuilderFns; |
| 14 |
use RadiusTheme\SB\Models\TemplateSettings; |
| 15 |
use RadiusTheme\SB\Elementor\Render\Render; |
| 16 |
use RadiusTheme\SB\Elementor\Helper\RenderHelpers; |
| 17 |
|
| 18 |
defined( 'ABSPATH' ) || exit(); |
| 19 |
|
| 20 |
/** |
| 21 |
* Main ActionHooks class. |
| 22 |
*/ |
| 23 |
class ActionHooks { |
| 24 |
/** |
| 25 |
* Init Hooks. |
| 26 |
* |
| 27 |
* @return void |
| 28 |
*/ |
| 29 |
public static function init_hooks() { |
| 30 |
add_action( 'rtsb/before/save/options', [ __CLASS__, 'clear_cron_schedule' ], 10, 3 ); |
| 31 |
add_action( 'wp_head', [ __CLASS__, 'og_metatags_for_sharing' ], 1 ); |
| 32 |
add_action( 'woocommerce_share', [ __CLASS__, 'shopbuilder_share' ], 20 ); |
| 33 |
add_action( 'rtsb/wcqv/product/summary', [ __CLASS__, 'shopbuilder_share' ], 40 ); |
| 34 |
add_action( 'rtsb/shop/product/image', [ __CLASS__, 'render_image' ], 10, 2 ); |
| 35 |
|
| 36 |
add_action( |
| 37 |
'admin_init', |
| 38 |
function () { |
| 39 |
remove_post_type_support( BuilderFns::$post_type_tb, 'revisions' ); |
| 40 |
} |
| 41 |
); |
| 42 |
add_action( 'deleted_post', [ __CLASS__, 'deleted_post' ], 10, 2 ); |
| 43 |
add_action( 'rtsb/elements/render/before_query', [ __CLASS__, 'modify_wc_query_args' ] ); |
| 44 |
add_action( 'rtsb/elements/render/after_query', [ __CLASS__, 'reset_wc_query_args' ] ); |
| 45 |
// Cart Table. |
| 46 |
remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 ); |
| 47 |
add_action( 'woocommerce_cart_is_empty', [ __CLASS__, 'cart_is_empty' ], 10 ); |
| 48 |
/** |
| 49 |
* Notices. |
| 50 |
*/ |
| 51 |
remove_action( 'woocommerce_cart_is_empty', 'woocommerce_output_all_notices', 5 ); |
| 52 |
remove_action( 'woocommerce_shortcode_before_product_cat_loop', 'woocommerce_output_all_notices', 10 ); |
| 53 |
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10 ); |
| 54 |
remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 ); |
| 55 |
remove_action( 'woocommerce_before_cart', 'woocommerce_output_all_notices', 10 ); |
| 56 |
remove_action( 'woocommerce_before_checkout_form_cart_notices', 'woocommerce_output_all_notices', 10 ); |
| 57 |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_output_all_notices', 10 ); |
| 58 |
remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 5 ); |
| 59 |
remove_action( 'woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10 ); |
| 60 |
remove_action( 'woocommerce_before_lost_password_form', 'woocommerce_output_all_notices', 10 ); |
| 61 |
remove_action( 'before_woocommerce_pay', 'woocommerce_output_all_notices', 10 ); |
| 62 |
remove_action( 'woocommerce_before_reset_password_form', 'woocommerce_output_all_notices', 10 ); |
| 63 |
|
| 64 |
/** |
| 65 |
* Notices. |
| 66 |
*/ |
| 67 |
add_action( 'woocommerce_shortcode_before_product_cat_loop', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); |
| 68 |
add_action( 'woocommerce_before_shop_loop', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); |
| 69 |
add_action( 'woocommerce_before_single_product', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); |
| 70 |
add_action( 'woocommerce_before_cart', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); |
| 71 |
add_action( 'woocommerce_before_checkout_form_cart_notices', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); |
| 72 |
add_action( 'woocommerce_before_checkout_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); |
| 73 |
add_action( 'woocommerce_account_content', [ Fns::class, 'woocommerce_output_all_notices' ], 5 ); |
| 74 |
add_action( 'woocommerce_before_customer_login_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); |
| 75 |
add_action( 'woocommerce_before_lost_password_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); |
| 76 |
add_action( 'before_woocommerce_pay', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); |
| 77 |
add_action( 'woocommerce_before_reset_password_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); |
| 78 |
|
| 79 |
// Checkout Page. |
| 80 |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 ); |
| 81 |
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 ); |
| 82 |
add_action( 'woocommerce_before_checkout_form', [ __CLASS__, 'woocommerce_checkout_login_form' ], 10 ); |
| 83 |
add_action( 'woocommerce_before_checkout_form', [ __CLASS__, 'woocommerce_checkout_coupon_form' ], 10 ); |
| 84 |
// My Account Order Page. |
| 85 |
add_action( 'woocommerce_before_account_orders', [ __CLASS__, 'before_account_orders' ], 10 ); |
| 86 |
add_action( 'woocommerce_after_account_orders', [ __CLASS__, 'after_account_orders' ], 10 ); |
| 87 |
|
| 88 |
// Product Filter Widget Hooks. |
| 89 |
add_action( 'rtsb/before/archive/default/filter/items', [ __CLASS__,'default_filter_header' ], 10 ); |
| 90 |
add_action( 'rtsb/before/archive/default/filter/items', [ __CLASS__,'default_filter_search' ], 15 ); |
| 91 |
|
| 92 |
// WC Query modifier. |
| 93 |
if ( ! rtsb()->has_pro() ) { |
| 94 |
add_action( 'woocommerce_product_query', [ __CLASS__, 'query_modifier' ], 15 ); |
| 95 |
} |
| 96 |
|
| 97 |
add_action( 'switch_theme', [ __CLASS__, 'clear_cache' ] ); |
| 98 |
} |
| 99 |
/** |
| 100 |
* Clear scheduled cron events when a module is deactivated. |
| 101 |
* |
| 102 |
* Checks the given block ID against predefined schedules and clears |
| 103 |
* related cron hooks if the corresponding module is turned off. |
| 104 |
* |
| 105 |
* @param string $section_id Section identifier (not used in this function). |
| 106 |
* @param string $block_id Module/block identifier to check scheduled hooks. |
| 107 |
* @param array $rawOptions Module options array containing 'active' status. |
| 108 |
* |
| 109 |
* @return void |
| 110 |
*/ |
| 111 |
public static function clear_cron_schedule( $section_id, $block_id, $rawOptions ) { |
| 112 |
$schedule = [ |
| 113 |
'abandoned_cart_recovery' => [ |
| 114 |
'rtsb_abandoned_cart_recovery_action', |
| 115 |
'rtsb_send_abandoned_cart_emails', |
| 116 |
], |
| 117 |
'currency_switcher' => [ |
| 118 |
'update_exchange_rates_hourly', |
| 119 |
], |
| 120 |
]; |
| 121 |
if ( ! isset( $schedule[ $block_id ] ) ) { |
| 122 |
return; |
| 123 |
} |
| 124 |
if ( ! isset( $rawOptions['active'] ) ) { |
| 125 |
return; |
| 126 |
} |
| 127 |
if ( 'on' === $rawOptions['active'] ) { |
| 128 |
return; |
| 129 |
} |
| 130 |
// CLear All Custom Schedule If module disabled. |
| 131 |
foreach ( $schedule[ $block_id ] as $hook ) { |
| 132 |
wp_clear_scheduled_hook( $hook ); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* @param boolen $has_orders Order exist or not. |
| 138 |
* |
| 139 |
* @return void |
| 140 |
*/ |
| 141 |
public static function after_account_orders( $has_orders ) { |
| 142 |
if ( ! $has_orders ) { |
| 143 |
echo '</div>'; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* @param boolen $has_orders Order exist or not. |
| 149 |
* |
| 150 |
* @return void |
| 151 |
*/ |
| 152 |
public static function before_account_orders( $has_orders ) { |
| 153 |
if ( ! $has_orders ) { |
| 154 |
echo '<div class="rtsb-notice">'; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
/** |
| 160 |
* @return void |
| 161 |
*/ |
| 162 |
public static function woocommerce_checkout_coupon_form() { |
| 163 |
echo '<div class="rtsb-notice">'; |
| 164 |
woocommerce_checkout_coupon_form(); |
| 165 |
echo '</div>'; |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* @return void |
| 170 |
*/ |
| 171 |
public static function woocommerce_checkout_login_form() { |
| 172 |
echo '<div class="rtsb-notice">'; |
| 173 |
woocommerce_checkout_login_form(); |
| 174 |
echo '</div>'; |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* @return void |
| 179 |
*/ |
| 180 |
public static function cart_is_empty() { |
| 181 |
echo '<div class="rtsb-notice">'; |
| 182 |
wc_empty_cart_message(); |
| 183 |
echo '</div>'; |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* @param int $post_id Post Ids. |
| 188 |
* @param object $post Post Object. |
| 189 |
* |
| 190 |
* @return void |
| 191 |
*/ |
| 192 |
public static function deleted_post( $post_id, $post ) { |
| 193 |
if ( BuilderFns::$post_type_tb !== $post->post_type ) { |
| 194 |
return; |
| 195 |
} |
| 196 |
|
| 197 |
$options = BuilderFns::option_name_for_specific_product_set_default( $post_id ); |
| 198 |
TemplateSettings::instance()->delete_option( $options ); |
| 199 |
|
| 200 |
$template_options = BuilderFns::option_name_by_template_id( $post_id ); |
| 201 |
TemplateSettings::instance()->delete_option( $template_options ); |
| 202 |
|
| 203 |
$archive_options = BuilderFns::archive_option_name_by_template_id( $post_id ); |
| 204 |
TemplateSettings::instance()->delete_option( $archive_options ); |
| 205 |
|
| 206 |
$category_options = BuilderFns::option_name_for_specific_category_set_default( $post_id ); |
| 207 |
TemplateSettings::instance()->delete_option( $category_options ); |
| 208 |
|
| 209 |
$selected_category_options = BuilderFns::archive_option_name_by_template_id( $post_id ); |
| 210 |
TemplateSettings::instance()->delete_option( $selected_category_options ); |
| 211 |
|
| 212 |
// Delete Data From Options. |
| 213 |
$options_product_selected_cat = BuilderFns::option_name_product_page_selected_cat( $post_id ); |
| 214 |
$cat_list = TemplateSettings::instance()->get_option( $options_product_selected_cat ); |
| 215 |
if ( ! empty( $cat_list ) ) { |
| 216 |
foreach ( $cat_list as $old_slug ) { |
| 217 |
$OldcatList = get_term_by( 'slug', $old_slug, 'product_cat' ); |
| 218 |
if ( ! empty( $OldcatList ) && ! is_wp_error( $OldcatList ) ) { |
| 219 |
delete_term_meta( $OldcatList->term_id, BuilderFns::$categories_product_page_template, $post_id ); |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
TemplateSettings::instance()->delete_option( $options_product_selected_cat ); |
| 224 |
|
| 225 |
$set_default_option = BuilderFns::option_name_product_page_specific_cat_set_default( $post_id ); |
| 226 |
TemplateSettings::instance()->delete_option( $set_default_option ); |
| 227 |
|
| 228 |
// Tags Remove. |
| 229 |
$options_product_selected_tag = BuilderFns::option_name_product_page_selected_tag( $post_id ); |
| 230 |
$tag_list = TemplateSettings::instance()->get_option( $options_product_selected_tag ); |
| 231 |
if ( ! empty( $tag_list ) ) { |
| 232 |
foreach ( $tag_list as $old_slug ) { |
| 233 |
$OldTagList = get_term_by( 'slug', $old_slug, 'product_tag' ); |
| 234 |
if ( ! empty( $OldTagList ) && ! is_wp_error( $OldTagList ) ) { |
| 235 |
delete_term_meta( $OldTagList->term_id, BuilderFns::$tags_product_page_template, $post_id ); |
| 236 |
} |
| 237 |
} |
| 238 |
} |
| 239 |
TemplateSettings::instance()->delete_option( $options_product_selected_tag ); |
| 240 |
|
| 241 |
// Tag Set Default Option. |
| 242 |
$tag_set_default_option = BuilderFns::option_name_product_page_specific_tag_set_default( $post_id ); |
| 243 |
TemplateSettings::instance()->delete_option( $tag_set_default_option ); |
| 244 |
|
| 245 |
global $wpdb; |
| 246 |
// Prepare and execute the SQL query. |
| 247 |
$sql = $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_products_meta, $post_id ); |
| 248 |
$wpdb->query( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 249 |
|
| 250 |
// Prepare and execute the SQL query. |
| 251 |
$sql = $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_archive_meta, $post_id ); |
| 252 |
$wpdb->query( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 253 |
} |
| 254 |
/** |
| 255 |
* Meta tags for social sharing. |
| 256 |
* |
| 257 |
* @return void |
| 258 |
*/ |
| 259 |
public static function shopbuilder_share() { |
| 260 |
$generalList = GeneralList::instance()->get_data(); |
| 261 |
|
| 262 |
if ( |
| 263 |
empty( $generalList['social_share']['share_platforms_to_product_page'] ) || |
| 264 |
'on' !== $generalList['social_share']['share_platforms_to_product_page'] || |
| 265 |
empty( $generalList['social_share']['share_platforms'] ) |
| 266 |
) { |
| 267 |
return; |
| 268 |
} |
| 269 |
|
| 270 |
$share_platforms = []; |
| 271 |
|
| 272 |
foreach ( $generalList['social_share']['share_platforms'] as $value ) { |
| 273 |
$share_platforms[ $value ] = [ |
| 274 |
'share_items' => $value, |
| 275 |
'share_text' => ucwords( $value ), |
| 276 |
]; |
| 277 |
} |
| 278 |
|
| 279 |
$settings['share_platforms'] = $share_platforms; |
| 280 |
$settings['layout'] = ! empty( $generalList['social_share']['share_icon_layout'] ) ? $generalList['social_share']['share_icon_layout'] : 1; |
| 281 |
$settings['show_share_icon'] = 1; |
| 282 |
|
| 283 |
/** |
| 284 |
* Implement Later ! empty( $generalList['social_share']['share_icon_show_to_product_page'] ) && 'on' === $generalList['social_share']['share_icon_show_to_product_page']; |
| 285 |
*/ |
| 286 |
Fns::print_html( Render::instance()->social_share_view( 'elementor/general/social-share', $settings ), true ); |
| 287 |
} |
| 288 |
|
| 289 |
/** |
| 290 |
* Meta tags for social sharing. |
| 291 |
* |
| 292 |
* @return void |
| 293 |
*/ |
| 294 |
public static function og_metatags_for_sharing() { |
| 295 |
global $post; |
| 296 |
|
| 297 |
if ( ! isset( $post ) ) { |
| 298 |
return; |
| 299 |
} |
| 300 |
|
| 301 |
if ( ! is_singular( 'product' ) ) { |
| 302 |
return; |
| 303 |
} |
| 304 |
|
| 305 |
Fns::print_html( '<meta property="og:url" content="' . get_the_permalink() . '" />', true ); |
| 306 |
Fns::print_html( '<meta property="og:type" content="article" />', true ); |
| 307 |
Fns::print_html( '<meta property="og:title" content="' . $post->post_title . '" />', true ); |
| 308 |
Fns::print_html( '<meta property="og:description" content="' . wp_trim_words( $post->post_content, 150 ) . '" />' ); |
| 309 |
|
| 310 |
$attachment = get_the_post_thumbnail_url(); |
| 311 |
|
| 312 |
if ( ! empty( $attachment ) ) { |
| 313 |
Fns::print_html( '<meta property="og:image" content="' . $attachment . '" />', true ); |
| 314 |
} |
| 315 |
|
| 316 |
Fns::print_html( '<meta property="og:site_name" content="' . get_bloginfo( 'name' ) . '" />', true ); |
| 317 |
Fns::print_html( '<meta name="twitter:card" content="summary" />', true ); |
| 318 |
} |
| 319 |
|
| 320 |
/** |
| 321 |
* Render image. |
| 322 |
* |
| 323 |
* @param array $args Image args. |
| 324 |
* |
| 325 |
* @return void |
| 326 |
*/ |
| 327 |
public static function render_image( $args ) { |
| 328 |
if ( $args['image_link'] ) { |
| 329 |
$aria_label = esc_attr( |
| 330 |
/* translators: Product Name */ |
| 331 |
sprintf( __( 'Image link for Product: %s', 'shopbuilder' ), $args['title'] ) |
| 332 |
); |
| 333 |
?> |
| 334 |
<figure> |
| 335 |
<a class="woocommerce-LoopProduct-link rtsb-img-link" href="<?php echo esc_url( $args['p_link'] ); ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"> |
| 336 |
<?php |
| 337 |
Fns::get_product_image( $args['img_html'], $args['hover_img_html'] ); |
| 338 |
?> |
| 339 |
</a> |
| 340 |
</figure> |
| 341 |
<?php |
| 342 |
} else { |
| 343 |
echo '<figure class="rtsb-img-link">'; |
| 344 |
Fns::get_product_image( $args['img_html'], $args['hover_img_html'] ); |
| 345 |
echo '</figure>'; |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
/** |
| 350 |
* Modify WooCommerce query arguments for product retrieval. |
| 351 |
* |
| 352 |
* @param array $settings The settings array. |
| 353 |
* |
| 354 |
* @return void |
| 355 |
*/ |
| 356 |
public static function modify_wc_query_args( $settings ) { |
| 357 |
if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) || |
| 358 |
( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) { |
| 359 |
add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_or' ], 10, 2 ); |
| 360 |
} |
| 361 |
if ( ( isset( $settings['tax_relation'] ) && 'AND' === $settings['tax_relation'] ) || |
| 362 |
( isset( $settings['relation'] ) && 'AND' === $settings['relation'] ) ) { |
| 363 |
add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_and' ], 10, 2 ); |
| 364 |
} |
| 365 |
|
| 366 |
if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { |
| 367 |
add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_outofstock' ] ); |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
/** |
| 372 |
* Reset WooCommerce query arguments for product retrieval. |
| 373 |
* |
| 374 |
* @param array $settings The settings array. |
| 375 |
* |
| 376 |
* @return void |
| 377 |
*/ |
| 378 |
public static function reset_wc_query_args( $settings ) { |
| 379 |
if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) || |
| 380 |
( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) { |
| 381 |
remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_or' ] ); |
| 382 |
} |
| 383 |
if ( ( isset( $settings['tax_relation'] ) && 'AND' === $settings['tax_relation'] ) || |
| 384 |
( isset( $settings['relation'] ) && 'AND' === $settings['relation'] ) ) { |
| 385 |
remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_and' ] ); |
| 386 |
} |
| 387 |
|
| 388 |
if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { |
| 389 |
remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_outofstock' ] ); |
| 390 |
} |
| 391 |
} |
| 392 |
/** |
| 393 |
* Display a filter header. |
| 394 |
* |
| 395 |
* @param array $settings The settings. |
| 396 |
* |
| 397 |
* @return void |
| 398 |
*/ |
| 399 |
public static function default_filter_header( $settings ) { |
| 400 |
if ( empty( $settings['show_filter_header'] ) && empty( $settings['filter_header_text'] ) ) { |
| 401 |
return; |
| 402 |
} |
| 403 |
|
| 404 |
$wrapper_class = 'rtsb-default-filter-header '; |
| 405 |
|
| 406 |
?> |
| 407 |
|
| 408 |
<div class="<?php echo esc_attr( $wrapper_class ); ?>"> |
| 409 |
<h3><?php echo esc_html( $settings['filter_header_text'] ); ?></h3> |
| 410 |
</div> |
| 411 |
|
| 412 |
<?php |
| 413 |
} |
| 414 |
/** |
| 415 |
* Display a filter search form. |
| 416 |
* |
| 417 |
* @param array $settings The settings. |
| 418 |
* |
| 419 |
* @return void |
| 420 |
*/ |
| 421 |
public static function default_filter_search( $settings ) { |
| 422 |
if ( empty( $settings['search_form'] ) ) { |
| 423 |
return; |
| 424 |
} |
| 425 |
|
| 426 |
$title = [ |
| 427 |
'title' => ! empty( $settings['search_title'] ) ? $settings['search_title'] : '', |
| 428 |
'show_icon' => ! empty( $settings['show_search_title_icon'] ), |
| 429 |
'icon' => ! empty( $settings['filter_search_title_icon'] ) ? $settings['filter_search_title_icon'] : [], |
| 430 |
]; |
| 431 |
$placeholder = ! empty( $settings['search_placeholder'] ) ? $settings['search_placeholder'] : ''; |
| 432 |
$btn_icon = ! empty( $settings['search_title_icon'] ) ? $settings['search_title_icon'] : []; |
| 433 |
$wrapper_class = 'rtsb-default-filter-search rtsb-default-product-search'; |
| 434 |
$unique_id = substr( uniqid(), -6 ); |
| 435 |
$search_term = isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 436 |
?> |
| 437 |
|
| 438 |
<div class="<?php echo esc_attr( $wrapper_class ); ?>"> |
| 439 |
<?php |
| 440 |
Fns::print_html( RenderHelpers::get_default_filter_title( $title ) ); |
| 441 |
?> |
| 442 |
<div class="default-search-content"> |
| 443 |
<div class="woocommerce-product-search<?php echo ! empty( $search_term ) ? ' active' : ''; ?>"> |
| 444 |
<div class="search-input"> |
| 445 |
<label class="screen-reader-text" for="rtsb-product-default-search-form-<?php echo esc_attr( $unique_id ); ?>"><?php echo esc_html( $placeholder ); ?></label> |
| 446 |
<input type="search" id="rtsb-product-default-search-form-<?php echo esc_attr( $unique_id ); ?>" class="rtsb-default-search-field" placeholder="<?php echo esc_html( $placeholder ); ?>" value="<?php echo esc_attr( $search_term ); ?>" name="s" autocomplete="off"> |
| 447 |
</div> |
| 448 |
<button class="rtsb-search-submit"> |
| 449 |
<?php |
| 450 |
|
| 451 |
Fns::print_html( Fns::icons_manager( $btn_icon, 'search-icon' ) ); |
| 452 |
|
| 453 |
?> |
| 454 |
<span></span> |
| 455 |
</button> |
| 456 |
</div> |
| 457 |
</div> |
| 458 |
</div> |
| 459 |
|
| 460 |
<?php |
| 461 |
} |
| 462 |
/** |
| 463 |
* Query modifier. |
| 464 |
* |
| 465 |
* @param object $query Query. |
| 466 |
* @return object |
| 467 |
*/ |
| 468 |
public static function query_modifier( $query ) { |
| 469 |
$onsale_filter = isset( $_GET['sale_filter'] ) ? sanitize_text_field( wp_unslash( $_GET['sale_filter'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 470 |
$on_sale_products = wc_get_product_ids_on_sale(); |
| 471 |
|
| 472 |
if ( 'onsale' === $onsale_filter ) { |
| 473 |
$query->set( 'post__in', ! empty( $on_sale_products ) ? $on_sale_products : [ 0 ] ); |
| 474 |
} elseif ( 'regular' === $onsale_filter ) { |
| 475 |
$query->set( 'post__not_in', $on_sale_products ); |
| 476 |
} |
| 477 |
|
| 478 |
return $query; |
| 479 |
} |
| 480 |
|
| 481 |
/** |
| 482 |
* Delete cache when switching to another theme. |
| 483 |
* |
| 484 |
* @return void |
| 485 |
*/ |
| 486 |
public static function clear_cache() { |
| 487 |
Cache::clear_all_cache(); |
| 488 |
} |
| 489 |
} |
| 490 |
|