| @@ -38,14 +38,111 @@ | ||
| 38 | 38 | ); |
| 39 | 39 | add_action( 'deleted_post', [ __CLASS__, 'deleted_post' ], 10, 2 ); |
| 40 | 40 | add_action( 'rtsb/elements/render/before_query', [ __CLASS__, 'modify_wc_query_args' ] ); |
| 41 | 41 | add_action( 'rtsb/elements/render/after_query', [ __CLASS__, 'reset_wc_query_args' ] ); |
| 42 | + // Cart Table. | |
| 43 | + remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 ); | |
| 44 | + add_action( 'woocommerce_cart_is_empty', [ __CLASS__, 'cart_is_empty' ], 10 ); | |
| 45 | + /** | |
| 46 | + * Notices. | |
| 47 | + */ | |
| 48 | + remove_action( 'woocommerce_cart_is_empty', 'woocommerce_output_all_notices', 5 ); | |
| 49 | + remove_action( 'woocommerce_shortcode_before_product_cat_loop', 'woocommerce_output_all_notices', 10 ); | |
| 50 | + remove_action( 'woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10 ); | |
| 51 | + remove_action( 'woocommerce_before_single_product', 'woocommerce_output_all_notices', 10 ); | |
| 52 | + remove_action( 'woocommerce_before_cart', 'woocommerce_output_all_notices', 10 ); | |
| 53 | + remove_action( 'woocommerce_before_checkout_form_cart_notices', 'woocommerce_output_all_notices', 10 ); | |
| 54 | + remove_action( 'woocommerce_before_checkout_form', 'woocommerce_output_all_notices', 10 ); | |
| 55 | + remove_action( 'woocommerce_account_content', 'woocommerce_output_all_notices', 5 ); | |
| 56 | + remove_action( 'woocommerce_before_customer_login_form', 'woocommerce_output_all_notices', 10 ); | |
| 57 | + remove_action( 'woocommerce_before_lost_password_form', 'woocommerce_output_all_notices', 10 ); | |
| 58 | + remove_action( 'before_woocommerce_pay', 'woocommerce_output_all_notices', 10 ); | |
| 59 | + remove_action( 'woocommerce_before_reset_password_form', 'woocommerce_output_all_notices', 10 ); | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Notices. | |
| 63 | + */ | |
| 64 | + // add_action( 'woocommerce_cart_is_empty', [ Fns::class, 'woocommerce_output_all_notices' ], 5 ); | |
| 65 | + add_action( 'woocommerce_shortcode_before_product_cat_loop', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 66 | + add_action( 'woocommerce_before_shop_loop', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 67 | + add_action( 'woocommerce_before_single_product', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 68 | + add_action( 'woocommerce_before_cart', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 69 | + add_action( 'woocommerce_before_checkout_form_cart_notices', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 70 | + add_action( 'woocommerce_before_checkout_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 71 | + add_action( 'woocommerce_account_content', [ Fns::class, 'woocommerce_output_all_notices' ], 5 ); | |
| 72 | + add_action( 'woocommerce_before_customer_login_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 73 | + add_action( 'woocommerce_before_lost_password_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 74 | + add_action( 'before_woocommerce_pay', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 75 | + add_action( 'woocommerce_before_reset_password_form', [ Fns::class, 'woocommerce_output_all_notices' ], 10 ); | |
| 76 | + | |
| 77 | + // Checkout Page. | |
| 78 | + remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 ); | |
| 79 | + remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 ); | |
| 80 | + add_action( 'woocommerce_before_checkout_form', [ __CLASS__, 'woocommerce_checkout_login_form' ], 10 ); | |
| 81 | + add_action( 'woocommerce_before_checkout_form', [ __CLASS__, 'woocommerce_checkout_coupon_form' ], 10 ); | |
| 82 | + // My Account Order Page. | |
| 83 | + add_action( 'woocommerce_before_account_orders', [ __CLASS__, 'before_account_orders' ], 10 ); | |
| 84 | + add_action( 'woocommerce_after_account_orders', [ __CLASS__, 'after_account_orders' ], 10 ); | |
| 42 | 85 | } |
| 86 | + | |
| 87 | + | |
| 43 | 88 | /** |
| 44 | - * Meta tags for social sharing. | |
| 89 | + * @param boolen $has_orders Order exist or not. | |
| 45 | 90 | * |
| 46 | 91 | * @return void |
| 47 | 92 | */ |
| 93 | + public static function after_account_orders( $has_orders ) { | |
| 94 | + if ( ! $has_orders ) { | |
| 95 | + echo '</div>'; | |
| 96 | + } | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * @param boolen $has_orders Order exist or not. | |
| 101 | + * | |
| 102 | + * @return void | |
| 103 | + */ | |
| 104 | + public static function before_account_orders( $has_orders ) { | |
| 105 | + if ( ! $has_orders ) { | |
| 106 | + echo '<div class="rtsb-notice">'; | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + | |
| 111 | + /** | |
| 112 | + * @return void | |
| 113 | + */ | |
| 114 | + public static function woocommerce_checkout_coupon_form() { | |
| 115 | + echo '<div class="rtsb-notice">'; | |
| 116 | + woocommerce_checkout_coupon_form(); | |
| 117 | + echo '</div>'; | |
| 118 | + } | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * @return void | |
| 122 | + */ | |
| 123 | + public static function woocommerce_checkout_login_form() { | |
| 124 | + echo '<div class="rtsb-notice">'; | |
| 125 | + woocommerce_checkout_login_form(); | |
| 126 | + echo '</div>'; | |
| 127 | + } | |
| 128 | + | |
| 129 | + /** | |
| 130 | + * @return void | |
| 131 | + */ | |
| 132 | + public static function cart_is_empty() { | |
| 133 | + echo '<div class="rtsb-notice">'; | |
| 134 | + wc_empty_cart_message(); | |
| 135 | + echo '</div>'; | |
| 136 | + } | |
| 137 | + | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * @param int $post_id Post Ids. | |
| 141 | + * @param object $post Post Object. | |
| 142 | + * | |
| 143 | + * @return void | |
| 144 | + */ | |
| 48 | 145 | public static function deleted_post( $post_id, $post ) { |
| 49 | 146 | if ( BuilderFns::$post_type_tb !== $post->post_type ) { |
| 50 | 147 | return; |
| 51 | 148 | } |
| @@ -75,16 +172,15 @@ | ||
| 75 | 172 | TemplateSettings::instance()->delete_option( $selected_category_options ); |
| 76 | 173 | } |
| 77 | 174 | |
| 78 | 175 | global $wpdb; |
| 79 | - // Prepare and execute the SQL query. | |
| 176 | + // Prepare and execute the SQL query. | |
| 80 | 177 | $sql = $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_products_meta, $post_id ); |
| 81 | - $wpdb->query( $sql ); | |
| 178 | + $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 82 | 179 | |
| 83 | 180 | // Prepare and execute the SQL query. |
| 84 | 181 | $sql = $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_key = %s AND meta_value = %d", BuilderFns::$view_template_for_archive_meta, $post_id ); |
| 85 | - $wpdb->query( $sql ); | |
| 86 | - | |
| 182 | + $wpdb->query( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 87 | 183 | } |
| 88 | 184 | /** |
| 89 | 185 | * Meta tags for social sharing. |
| 90 | 186 | * |
| @@ -190,8 +286,12 @@ | ||
| 190 | 286 | if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) || |
| 191 | 287 | ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) { |
| 192 | 288 | add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ], 10, 2 ); |
| 193 | 289 | } |
| 290 | + | |
| 291 | + if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { | |
| 292 | + add_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_outofstock' ] ); | |
| 293 | + } | |
| 194 | 294 | } |
| 195 | 295 | |
| 196 | 296 | /** |
| 197 | 297 | * Reset WooCommerce query arguments for product retrieval. |
| @@ -203,7 +303,11 @@ | ||
| 203 | 303 | public static function reset_wc_query_args( $settings ) { |
| 204 | 304 | if ( ( isset( $settings['tax_relation'] ) && 'OR' === $settings['tax_relation'] ) || |
| 205 | 305 | ( isset( $settings['relation'] ) && 'OR' === $settings['relation'] ) ) { |
| 206 | 306 | remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args' ] ); |
| 307 | + } | |
| 308 | + | |
| 309 | + if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { | |
| 310 | + remove_filter( 'woocommerce_product_data_store_cpt_get_products_query', [ FilterHooks::class, 'extra_query_args_outofstock' ] ); | |
| 207 | 311 | } |
| 208 | 312 | } |
| 209 | 313 | } |