remove-add-to-cart-button-for-woocommerce
/
admin
/
class-remove-add-to-cart-button-woocommerce-admin.php
css
5 years ago
js
5 years ago
class-remove-add-to-cart-button-woocommerce-admin.php
5 years ago
index.php
5 years ago
class-remove-add-to-cart-button-woocommerce-admin.php
330 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * The admin-specific functionality of the plugin. |
| 5 | * |
| 6 | * @link https://wpartisan.net/ |
| 7 | * @since 1.0.0 |
| 8 | * |
| 9 | * @package Remove_Add_To_Cart_Button_Woocommerce |
| 10 | * @subpackage Remove_Add_To_Cart_Button_Woocommerce/admin |
| 11 | */ |
| 12 | /** |
| 13 | * The admin-specific functionality of the plugin. |
| 14 | * |
| 15 | * Defines the plugin name, version, and two examples hooks for how to |
| 16 | * enqueue the admin-specific stylesheet and JavaScript. |
| 17 | * |
| 18 | * @package Remove_Add_To_Cart_Button_Woocommerce |
| 19 | * @subpackage Remove_Add_To_Cart_Button_Woocommerce/admin |
| 20 | * @author wpArtisan <md.assaduzzaman.khan@gmail.com> |
| 21 | */ |
| 22 | class Remove_Add_To_Cart_Button_Woocommerce_Admin |
| 23 | { |
| 24 | /** |
| 25 | * The ID of this plugin. |
| 26 | * |
| 27 | * @since 1.0.0 |
| 28 | * @access private |
| 29 | * @var string $plugin_name The ID of this plugin. |
| 30 | */ |
| 31 | private $plugin_name ; |
| 32 | /** |
| 33 | * The version of this plugin. |
| 34 | * |
| 35 | * @since 1.0.0 |
| 36 | * @access private |
| 37 | * @var string $version The current version of this plugin. |
| 38 | */ |
| 39 | private $version ; |
| 40 | /** |
| 41 | * Initialize the class and set its properties. |
| 42 | * |
| 43 | * @since 1.0.0 |
| 44 | * @param string $plugin_name The name of this plugin. |
| 45 | * @param string $version The version of this plugin. |
| 46 | */ |
| 47 | public function __construct( $plugin_name, $version ) |
| 48 | { |
| 49 | $this->plugin_name = $plugin_name; |
| 50 | $this->version = $version; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Register the stylesheets for the admin area. |
| 55 | * |
| 56 | * @since 1.0.0 |
| 57 | */ |
| 58 | public function ratcw_enqueue_styles() |
| 59 | { |
| 60 | /** |
| 61 | * This function is provided for demonstration purposes only. |
| 62 | * |
| 63 | * An instance of this class should be passed to the run() function |
| 64 | * defined in Remove_Add_To_Cart_Button_Woocommerce_Loader as all of the hooks are defined |
| 65 | * in that particular class. |
| 66 | * |
| 67 | * The Remove_Add_To_Cart_Button_Woocommerce_Loader will then create the relationship |
| 68 | * between the defined hooks and the functions defined in this |
| 69 | * class. |
| 70 | */ |
| 71 | wp_enqueue_style( |
| 72 | $this->plugin_name, |
| 73 | plugin_dir_url( __FILE__ ) . 'css/remove-add-to-cart-button-woocommerce-admin.css', |
| 74 | array(), |
| 75 | $this->version, |
| 76 | 'all' |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Register the JavaScript for the admin area. |
| 82 | * |
| 83 | * @since 1.0.0 |
| 84 | */ |
| 85 | public function ratcw_enqueue_scripts() |
| 86 | { |
| 87 | /** |
| 88 | * This function is provided for demonstration purposes only. |
| 89 | * |
| 90 | * An instance of this class should be passed to the run() function |
| 91 | * defined in Remove_Add_To_Cart_Button_Woocommerce_Loader as all of the hooks are defined |
| 92 | * in that particular class. |
| 93 | * |
| 94 | * The Remove_Add_To_Cart_Button_Woocommerce_Loader will then create the relationship |
| 95 | * between the defined hooks and the functions defined in this |
| 96 | * class. |
| 97 | */ |
| 98 | wp_enqueue_script( |
| 99 | $this->plugin_name, |
| 100 | plugin_dir_url( __FILE__ ) . 'js/remove-add-to-cart-button-woocommerce-admin.js', |
| 101 | array( 'jquery' ), |
| 102 | $this->version, |
| 103 | false |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Register the Tab by hooking into the 'woocommerce_product_data_tabs' filter. |
| 109 | * |
| 110 | * @since 1.0.0 |
| 111 | */ |
| 112 | public function ratcw_remove_add_to_cart_button_data_tab( $product_data_tabs ) |
| 113 | { |
| 114 | $new_custom_tab['ratcw-remove-add-to-cart-button'] = array( |
| 115 | 'label' => esc_html__( 'Remove Add to Cart Button', 'remove-add-to-cart-button-woocommerce' ), |
| 116 | 'target' => 'ratcw_remove_add_to_cart_button_product_data', |
| 117 | 'class' => array( '' ), |
| 118 | ); |
| 119 | $insert_at_position = 3; |
| 120 | $tabs = array_slice( |
| 121 | $product_data_tabs, |
| 122 | 0, |
| 123 | $insert_at_position, |
| 124 | true |
| 125 | ); |
| 126 | $tabs = array_merge( $tabs, $new_custom_tab ); |
| 127 | $tabs = array_merge( $tabs, array_slice( |
| 128 | $product_data_tabs, |
| 129 | $insert_at_position, |
| 130 | null, |
| 131 | true |
| 132 | ) ); |
| 133 | return $tabs; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * CSS To Add Custom tab Icon. |
| 138 | * |
| 139 | * @since 1.0.0 |
| 140 | */ |
| 141 | public function ratcw_custom_style() |
| 142 | { |
| 143 | echo '<style>#woocommerce-product-data ul.wc-tabs li.ratcw-remove-add-to-cart-button_options a::before { |
| 144 | font-family: Dashicons; |
| 145 | content: "\\f153"; |
| 146 | }</style>' ; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Functions you can call to output the settings fields for remove add to cart button like text boxes, select boxes, etc. |
| 151 | * |
| 152 | * @since 1.0.0 |
| 153 | */ |
| 154 | public function ratcw_remove_add_to_cart_button_product_data_fields() |
| 155 | { |
| 156 | global $post, $wp_roles ; |
| 157 | $roles = $wp_roles->roles; |
| 158 | $countries_obj = new WC_Countries(); |
| 159 | $countries = $countries_obj->get_allowed_countries(); |
| 160 | if ( !empty($countries) ) { |
| 161 | $countries = array( |
| 162 | '' => esc_html__( 'Select countries', 'remove-add-to-cart-button-woocommerce' ), |
| 163 | ) + $countries; |
| 164 | } |
| 165 | ?> |
| 166 | <div id='ratcw_remove_add_to_cart_button_product_data' class='panel woocommerce_options_panel'> |
| 167 | <div class = 'options_group' > |
| 168 | <?php |
| 169 | $options_array = array( |
| 170 | '' => esc_html__( 'Please select', 'remove-add-to-cart-button-woocommerce' ), |
| 171 | 'for-all' => esc_html__( 'For All', 'remove-add-to-cart-button-woocommerce' ), |
| 172 | 'hide-only-for-visitor' => esc_html__( 'Only for Visitors', 'remove-add-to-cart-button-woocommerce' ), |
| 173 | ); |
| 174 | woocommerce_wp_select( array( |
| 175 | 'id' => 'ratcw_remove_cart_button_for', |
| 176 | 'value' => get_post_meta( get_the_ID(), 'ratcw_remove_cart_button_for', true ), |
| 177 | 'label' => esc_html__( 'Remove Add to Cart For :', 'remove-add-to-cart-button-woocommerce' ), |
| 178 | 'desc_tip' => true, |
| 179 | 'options' => $options_array, |
| 180 | 'description' => esc_attr__( 'Select a option to remove Add to Cart button for', 'remove-add-to-cart-button-woocommerce' ), |
| 181 | ) ); |
| 182 | woocommerce_wp_checkbox( array( |
| 183 | 'id' => 'ratcw_hide_price', |
| 184 | 'value' => esc_attr( get_post_meta( get_the_ID(), 'ratcw_hide_price', true ) ), |
| 185 | 'label' => esc_html__( 'Hide product price :', 'remove-add-to-cart-button-woocommerce' ), |
| 186 | 'desc_tip' => true, |
| 187 | 'description' => esc_attr__( 'Hide product price in frontend', 'remove-add-to-cart-button-woocommerce' ), |
| 188 | ) ); |
| 189 | woocommerce_wp_checkbox( array( |
| 190 | 'id' => 'ratcw_show_login_btn_when_cart_button_hidden', |
| 191 | 'value' => esc_attr( get_post_meta( get_the_ID(), 'ratcw_show_login_btn_when_cart_button_hidden', true ) ), |
| 192 | 'label' => esc_html__( 'Show Login/Register button ?', 'remove-add-to-cart-button-woocommerce' ), |
| 193 | 'desc_tip' => true, |
| 194 | 'description' => esc_attr__( 'Show Login/Register button when Add to Cart button is hidden in frontend', 'remove-add-to-cart-button-woocommerce' ), |
| 195 | ) ); |
| 196 | woocommerce_wp_textarea_input( array( |
| 197 | 'id' => 'ratcw_msg_instead_cart_button', |
| 198 | 'value' => esc_attr( get_post_meta( get_the_ID(), 'ratcw_msg_instead_cart_button', true ) ), |
| 199 | 'label' => esc_html__( 'Message :', 'remove-add-to-cart-button-woocommerce' ), |
| 200 | 'desc_tip' => true, |
| 201 | 'description' => esc_attr__( 'Message instead of Add to Cart for this product in frontend. If you don\'t show the message then nothings need to add here', 'remove-add-to-cart-button-woocommerce' ), |
| 202 | ) ); |
| 203 | ?> |
| 204 | </div> |
| 205 | <?php |
| 206 | |
| 207 | if ( ratcbw_fs()->is_not_paying() ) { |
| 208 | echo '<div class="un-con">' ; |
| 209 | echo '<h3>' . esc_html__( 'Awesome Premium Features in Remove Add to Cart Button for WooCommerce Plugin', 'remove-add-to-cart-button-woocommerce' ) . '</h3>' ; |
| 210 | echo '<ul>' ; |
| 211 | echo '<li><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Remove Add to Cart Button Based on User Rules', 'remove-add-to-cart-button-woocommerce' ) . '</li>' ; |
| 212 | echo '<li><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Remove Add to Cart Button Based on Countries', 'remove-add-to-cart-button-woocommerce' ) . '</li>' ; |
| 213 | echo '<li><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Set Category Wise Remove Add to Cart Button Conditions', 'remove-add-to-cart-button-woocommerce' ) . '</li>' ; |
| 214 | echo '<li><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Priority email support', 'remove-add-to-cart-button-woocommerce' ) . '</li>' ; |
| 215 | echo '</ul>' ; |
| 216 | echo '<a href="' . ratcbw_fs()->get_upgrade_url() . '" class="upgradebtn">' . esc_html__( 'Upgrade Now!', 'remove-product-description-woocommerce' ) . '</a>' ; |
| 217 | echo "</div>" ; |
| 218 | } |
| 219 | |
| 220 | ?> |
| 221 | </div> |
| 222 | <?php |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Save extra options values. |
| 227 | * |
| 228 | * @since 1.0.0 |
| 229 | */ |
| 230 | public function ratcw_save_fields( $id, $post ) |
| 231 | { |
| 232 | $ratcw_remove_cart_button_for = sanitize_text_field( $_POST['ratcw_remove_cart_button_for'] ); |
| 233 | $ratcw_hide_price = sanitize_text_field( $_POST['ratcw_hide_price'] ); |
| 234 | $ratcw_show_login_btn_when_cart_button_hidden = sanitize_text_field( $_POST['ratcw_show_login_btn_when_cart_button_hidden'] ); |
| 235 | $ratcw_msg_instead_cart_button = sanitize_textarea_field( $_POST['ratcw_msg_instead_cart_button'] ); |
| 236 | update_post_meta( $id, 'ratcw_remove_cart_button_for', $ratcw_remove_cart_button_for ); |
| 237 | update_post_meta( $id, 'ratcw_hide_price', $ratcw_hide_price ); |
| 238 | update_post_meta( $id, 'ratcw_show_login_btn_when_cart_button_hidden', $ratcw_show_login_btn_when_cart_button_hidden ); |
| 239 | update_post_meta( $id, 'ratcw_msg_instead_cart_button', $ratcw_msg_instead_cart_button ); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Add a new settings tab to the WooCommerce settings tabs array. |
| 244 | * |
| 245 | * @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab. |
| 246 | * @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab. |
| 247 | * @since 1.0.0 |
| 248 | */ |
| 249 | public function ratcw_add_settings_tab( $settings_tabs ) |
| 250 | { |
| 251 | $settings_tabs['remove-add-to-cart-button-settings'] = esc_html__( 'Visibility Settings', 'remove-add-to-cart-button-woocommerce' ); |
| 252 | return $settings_tabs; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function. |
| 257 | * |
| 258 | * @uses woocommerce_admin_fields() |
| 259 | * @uses $this->wcuo_settings_tab() |
| 260 | * @since 1.0.0 |
| 261 | */ |
| 262 | public function ratcw_settings_tab() |
| 263 | { |
| 264 | woocommerce_admin_fields( $this->ratcw_get_settings() ); |
| 265 | |
| 266 | if ( ratcbw_fs()->is_not_paying() ) { |
| 267 | echo '<div class="un-con">' ; |
| 268 | echo '<h3>' . esc_html__( 'Awesome Premium Features in Remove Add to Cart Button for WooCommerce Plugin', 'remove-add-to-cart-button-woocommerce' ) . '</h3>' ; |
| 269 | echo '<ul>' ; |
| 270 | echo '<li><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Remove Add to Cart Button Based on User Rules', 'remove-add-to-cart-button-woocommerce' ) . '</li>' ; |
| 271 | echo '<li><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Remove Add to Cart Button Based on Countries', 'remove-add-to-cart-button-woocommerce' ) . '</li>' ; |
| 272 | echo '<li><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Set Category Wise Remove Add to Cart Button Conditions', 'remove-add-to-cart-button-woocommerce' ) . '</li>' ; |
| 273 | echo '<li><span class="dashicons dashicons-yes"></span> ' . esc_html__( 'Priority email support', 'remove-add-to-cart-button-woocommerce' ) . '</li>' ; |
| 274 | echo '</ul>' ; |
| 275 | echo '<a href="' . ratcbw_fs()->get_upgrade_url() . '" class="upgradebtn">' . esc_html__( 'Upgrade Now!', 'remove-product-description-woocommerce' ) . '</a>' ; |
| 276 | echo "</div>" ; |
| 277 | } |
| 278 | |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Get all the settings for this plugin for @see woocommerce_admin_fields() function. |
| 283 | * |
| 284 | * @return array Array of settings for @see woocommerce_admin_fields() function. |
| 285 | * @since 1.0.0 |
| 286 | */ |
| 287 | public function ratcw_get_settings() |
| 288 | { |
| 289 | $settings = array( |
| 290 | 'section_title' => array( |
| 291 | 'name' => esc_html__( 'Visibility Settings', 'remove-add-to-cart-button-woocommerce' ), |
| 292 | 'type' => 'title', |
| 293 | 'desc' => '', |
| 294 | 'id' => 'ratcw_section_title', |
| 295 | ), |
| 296 | 'login_reg_page_url' => array( |
| 297 | 'name' => esc_html__( 'Enter Login/Register page URL here', 'remove-add-to-cart-button-woocommerce' ), |
| 298 | 'type' => 'text', |
| 299 | 'desc' => esc_html__( 'Enter Login/Register page URL here. By default it goes to My Account page for Login/Register if this field is empty', 'remove-add-to-cart-button-woocommerce' ), |
| 300 | 'desc_tip' => true, |
| 301 | 'id' => 'ratcw_login_reg_page_url', |
| 302 | ), |
| 303 | 'login_reg_button_text' => array( |
| 304 | 'name' => esc_html__( 'Enter Login/Register button label', 'remove-add-to-cart-button-woocommerce' ), |
| 305 | 'type' => 'text', |
| 306 | 'desc' => esc_html__( 'Enter Login/Register button label to show in frontend', 'remove-add-to-cart-button-woocommerce' ), |
| 307 | 'desc_tip' => true, |
| 308 | 'id' => 'ratcw_login_reg_button_text', |
| 309 | ), |
| 310 | 'section_end' => array( |
| 311 | 'type' => 'sectionend', |
| 312 | 'id' => 'ratcw_section_end', |
| 313 | ), |
| 314 | ); |
| 315 | return apply_filters( 'wc_remove_add_to_cart_button_settings', $settings ); |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function. |
| 320 | * |
| 321 | * @uses woocommerce_update_options() |
| 322 | * @uses $this->get_settings() |
| 323 | * @since 1.0.0 |
| 324 | */ |
| 325 | public function ratcw_update_settings() |
| 326 | { |
| 327 | woocommerce_update_options( $this->ratcw_get_settings() ); |
| 328 | } |
| 329 | |
| 330 | } |