Changeset 3238430
- Timestamp:
- 02/11/2025 08:53:00 AM (4 weeks ago)
- Location:
- wc-custom-add-to-cart-labels/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
wc-custom-add-to-cart-labels/trunk/readme.txt
r2324950 r3238430 4 4 Tags: add to cart, add to cart label, woocommerce, woocommerce add to cart, add to cart text, change add to cart, per product type, single product, single product page, archives, shop page, change button, change label, button label, simple, variable, grouped, external 5 5 Requires at least: 4.5.0 6 Tested up to: 5.4.27 Stable tag: 1. 36 Tested up to: 6.7.1 7 Stable tag: 1.5 8 8 WC requires at least: 3.0 9 WC tested up to: 4.2.09 WC tested up to: 9.6.1 10 10 License: GPLv3 or later License 11 11 URI: http://www.gnu.org/licenses/gpl-3.0.html 12 12 13 This plugin lets you change the “add to cart” labels on all single product pages (per product type) and also on archive/shop page (per product type) 13 Customize add-to-cart labels and styles for each WooCommerce product type. Easily adjust button text, colors, font size, borders, and border radius on single product and shop/archive pages via a dedicated WooCommerce settings tab. 14 14 15 15 16 16 == Description == 17 17 18 This plugin lets you customize the “add to cart” button labels on single product pages (per product type) and also on archive/shop page (per product type) 18 Customize add-to-cart labels and styles for each WooCommerce product type. Easily adjust button text, colors, font size, borders, and border radius on single product and shop/archive pages via a dedicated WooCommerce settings tab. 19 19 20 20 = Single products = … … 38 38 = Features = 39 39 40 * Compatible with latest WooCommerce (3.0.0 and up) 41 * Supports ASCII special characters in labels 42 * Supports Unicode characters in labels 43 * Supports HTML5 characters in labels 44 * Supports Emojis in labels (http://getemoji.com/ and http://www.copypastecharacter.com/emojis) 40 * Supports ASCII, Unicode, HTML5, and Emoji characters in labels 41 * Customizable add-to-cart labels per product type (single and shop/archive pages) 42 * Configurable button styles: background color, text color, font size, border, and border radius 45 43 46 44 … … 49 47 1. Download the plugin & install it to your `wp-content/plugins` folder (or use the Plugins menu through the WordPress Administration section) 50 48 2. Activate the plugin 51 3. Navigate to ** WooCommerce > Settings > Products > Change “add to cart” labels **. 52 4. Customise your labels. 53 5. Save and enjoy! 49 3. Navigate to ** WooCommerce > Settings > Add to Cat Button tab **. 50 4. Select the product type from the submenu items (all product types are added to their own submenu) 51 5. Customise your buttons. 52 6. Save and enjoy! 54 53 55 54 … … 63 62 64 63 = Q: Where can I go if I find an issue or want to recommend a feature? = 65 A: You can submit a issues / feature requests on the [Public GitHub Repository]().64 A: You can submit a issues / feature requests at [Orca Plugin Support](https://orcawp.com/contact). 66 65 67 66 == Screenshots == … … 83 82 * Added support for subscription and subscription variable products 84 83 * Fixed Call to a member function get_type() on null issue with Gutenberg 84 85 = 1.5 = 86 * Restructured the plugin into a modular, multi‑file architecture with separate admin and frontend classes. 87 * Added customizable styling options—including background color, text color, font size, border, and border radius—for add‑to‑cart buttons on both single product and archive/shop pages. 88 * Improved product handling to fix “Call to a member function get_type() on null” issues. 89 90 == Upgrade Notice == 91 92 = 1.5 = 93 * Restructured the plugin into a modular, multi‑file architecture with separate admin and frontend classes. 94 * Added customizable styling options—including background color, text color, font size, border, and border radius—for add‑to‑cart buttons on both single product and archive/shop pages. 95 * Improved product handling to fix “Call to a member function get_type() on null” issues. -
wc-custom-add-to-cart-labels/trunk/wc-custom-add-to-cart-labels.php
r2324950 r3238430 4 4 Plugin Name: WC Custom Add to Cart labels 5 5 Plugin URI: https://profiles.wordpress.org/rynald0s 6 Description: This plugin lets you change the "add to cart" labels on single product pages (per product type) and archive / shop page (per product type).6 Description: Customize add-to-cart labels and styles for each WooCommerce product type. Easily adjust button text, colors, font size, borders, and border radius on single product and shop/archive pages via a dedicated WooCommerce settings tab. 7 7 Author: Rynaldo Stoltz 8 Author URI: https:// github.com/rynaldos9 Version: 1. 38 Author URI: https://orcawp.com 9 Version: 1.5 10 10 License: GPLv3 or later License 11 11 URI: http://www.gnu.org/licenses/gpl-3.0.html 12 12 */ 13 13 14 if ( ! defined( 'ABSPATH' ) ) { 15 exit; // Exit if accessed directly 14 // Exit if accessed directly. 15 if ( ! defined( 'ABSPATH' ) ) { 16 exit; 16 17 } 17 18 18 /** 19 * Check if WooCommerce is active 20 **/ 21 22 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 23 24 /** 25 * Add settings 26 */ 27 28 function catcl_section( $sections ) { 29 $sections['catcl_section'] = __( 'Add to cart button labels', 'woocommerce' ); 30 return $sections; 19 // Check if WooCommerce is active. 20 if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 21 return; 31 22 } 32 23 33 add_filter( 'woocommerce_get_sections_products', 'catcl_section' ); 24 // Define plugin constants. 25 define( 'WC_CUSTOM_ATC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 26 define( 'WC_CUSTOM_ATC_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 34 27 35 36 function catcl_settings( $settings, $current_section ) { 37 38 39 /** 40 * Check the current section is what we want 41 **/ 42 43 if ( 'catcl_section' === $current_section ) { 44 45 $catcl_settings[] = array( 'title' => __( 'Change the "add to cart" button label on single product pages (per product type)', 'woocommerce' ), 'type' => 'title', 'id' => 'wc_atc_change' ); 46 47 $catcl_settings[] = array( 48 'title' => __( 'Simple products', 'woocommerce' ), 49 'desc' => 'This will change the "add to cart" label shown on single product page of simple product type', 50 'id' => 'simple_button_text_single', 51 'type' => 'text', 52 'placeholder' => 'Add to cart', 53 'css' => 'min-width:350px;', 54 ); 55 56 $catcl_settings[] = array( 57 'title' => __( 'Grouped products', 'woocommerce' ), 58 'desc' => 'This will change the "add to cart" label shown on single product page of grouped product type', 59 'id' => 'grouped_button_text_single', 60 'type' => 'text', 61 'placeholder' => 'Add to cart', 62 'css' => 'min-width:350px;', 63 ); 64 65 $catcl_settings[] = array( 66 'title' => __( 'External products', 'woocommerce' ), 67 'desc' => 'This will change the "add to cart" label shown on single product page of external product type', 68 'id' => 'external_button_text_single', 69 'type' => 'text', 70 'placeholder' => 'Add to cart', 71 'css' => 'min-width:350px;', 72 ); 73 74 $catcl_settings[] = array( 75 'title' => __( 'Variable products', 'woocommerce' ), 76 'desc' => 'This will change the "add to cart" label shown on single product page of variable product type', 77 'id' => 'variable_button_text_single', 78 'type' => 'text', 79 'placeholder' => 'Add to cart', 80 'css' => 'min-width:350px;', 81 ); 82 83 $catcl_settings[] = array( 84 'title' => __( 'Bookable products', 'woocommerce' ), 85 'desc' => 'This will change the "add to cart" label shown on single product page of bookable product type', 86 'id' => 'booking_button_text_single', 87 'type' => 'text', 88 'placeholder' => 'Add to cart', 89 'css' => 'min-width:350px;', 90 ); 91 92 $catcl_settings[] = array( 93 'title' => __( 'Subscription products', 'woocommerce-subscriptions' ), 94 'desc' => 'This will change the "add to cart" label shown on single product page of subscription product type', 95 'id' => 'subs_button_text_single', 96 'type' => 'text', 97 'placeholder' => 'Sign up now', 98 'css' => 'min-width:350px;', 99 ); 100 101 $catcl_settings[] = array( 102 'title' => __( 'Variable subscription products', 'woocommerce-subscriptions' ), 103 'desc' => 'This will change the "add to cart" label shown on the single product page of variable subscription product type', 104 'id' => 'subs_var_button_text_single', 105 'type' => 'text', 106 'placeholder' => 'Sign up now', 107 'css' => 'min-width:350px;', 108 ); 109 110 $catcl_settings[] = array( 'type' => 'sectionend', 'id' => 'wc_atc_change' ); 111 112 $catcl_settings[] = array( 'title' => __( 'Change the "add to cart" button label on archive / shop page (per product type)', 'woocommerce' ), 'type' => 'title', 'id' => 'wc_atc_change' ); 113 114 $catcl_settings[] = array( 115 'title' => __( 'Simple products (archive)', 'woocommerce' ), 116 'desc' => 'This will change the "add to cart" label on simple products that are shown on the archive page', 117 'id' => 'simple_button_text', 118 'type' => 'text', 119 'placeholder' => 'Add to cart', 120 'css' => 'min-width:350px;', 121 ); 122 123 $catcl_settings[] = array( 124 'title' => __( 'Grouped products (archive)', 'woocommerce' ), 125 'desc' => 'This will change the "add to cart" label on grouped products that are shown on the archive page', 126 'id' => 'grouped_button_text', 127 'type' => 'text', 128 'placeholder' => 'Add to cart', 129 'css' => 'min-width:350px;', 130 ); 131 132 $catcl_settings[] = array( 133 'title' => __( 'External products (archive)', 'woocommerce' ), 134 'desc' => 'This will change the "add to cart" label on external products that are shown on the archive page', 135 'id' => 'external_button_text', 136 'type' => 'text', 137 'placeholder' => 'Add to cart', 138 'css' => 'min-width:350px;', 139 ); 140 141 $catcl_settings[] = array( 142 'title' => __( 'Variable products (archive)', 'woocommerce' ), 143 'desc' => 'This will change the "add to cart" label on variable products that are shown on the archive page', 144 'id' => 'variable_button_text', 145 'type' => 'text', 146 'placeholder' => 'Add to cart', 147 'css' => 'min-width:350px;', 148 ); 149 150 $catcl_settings[] = array( 151 'title' => __( 'Bookable products (archive)', 'woocommerce' ), 152 'desc' => 'This will change the "add to cart" label on bookable products that are shown on the archive page', 153 'id' => 'booking_button_text', 154 'type' => 'text', 155 'placeholder' => 'Add to cart', 156 'css' => 'min-width:350px;', 157 ); 158 159 $catcl_settings[] = array( 160 'title' => __( 'Subscription products (archive)', 'woocommerce-subscriptions' ), 161 'desc' => 'This will change the "add to cart" label on subscription products that are shown on the archive page', 162 'id' => 'subs_button_text', 163 'type' => 'text', 164 'placeholder' => 'Sign up now', 165 'css' => 'min-width:350px;', 166 ); 167 168 $catcl_settings[] = array( 169 'title' => __( 'Variable subscription products (archive)', 'woocommerce-subscriptions' ), 170 'desc' => 'This will change the "add to cart" label on variable subscription products that are shown on the archive page', 171 'id' => 'subs_var_button_text', 172 'type' => 'text', 173 'placeholder' => 'Sign up now', 174 'css' => 'min-width:350px;', 175 ); 176 177 $catcl_settings[] = array( 'type' => 'sectionend', 'id' => 'wc_atc_change' ); 178 return $catcl_settings; 179 } else { 180 return $settings; 181 } 182 28 // Include our required classes. 29 if ( ! class_exists( 'WC_Custom_ATC_Admin' ) ) { 30 require_once WC_CUSTOM_ATC_PLUGIN_DIR . 'includes/class-wc-custom-atc-admin.php'; 31 } 32 if ( ! class_exists( 'WC_Custom_ATC_Frontend' ) ) { 33 require_once WC_CUSTOM_ATC_PLUGIN_DIR . 'includes/class-wc-custom-atc-frontend.php'; 183 34 } 184 35 185 add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' ); 186 add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_woocommerce_product_add_to_cart_text' ); 187 add_filter( 'woocommerce_booking_single_add_to_cart_text', 'custom_woocommerce_product_add_to_cart_text' ); 188 189 function custom_woocommerce_product_add_to_cart_text($text) { 190 global $product; 191 192 if (!isset ($product) || !is_object ($product)) 193 return $text; 194 195 $product_type = $product->get_type(); 196 197 198 if (is_product()) { 199 200 switch ( $product_type ) { 201 case 'simple': 202 return __( $options = catcl_get_settings( 'simple_button_text_single'), 'woocommerce' ); 203 break; 204 case 'grouped': 205 return __( $options = catcl_get_settings( 'grouped_button_text_single'), 'woocommerce' ); 206 break; 207 case 'external': 208 return __( $options = catcl_get_settings( 'external_button_text_single'), 'woocommerce' ); 209 break; 210 case 'variable': 211 return __( $options = catcl_get_settings( 'variable_button_text_single'), 'woocommerce' ); 212 break; 213 case 'booking': 214 return __( $options = catcl_get_settings( 'booking_button_text_single'), 'woocommerce-bookings' ); 215 break; 216 case 'subscription': 217 return __( $options = catcl_get_settings( 'subs_button_text_single'), 'woocommerce-subscriptions' ); 218 break; 219 case 'variable-subscription': 220 return __( $options = catcl_get_settings( 'subs_var_button_text_single'), 'woocommerce-subscriptions' ); 221 break; 222 default: 223 return __( 'Read more', 'woocommerce' ); 224 } 225 } 226 else { 227 228 switch ( $product_type ) { 229 case 'simple': 230 return __( $options = catcl_get_settings( 'simple_button_text'), 'woocommerce' ); 231 break; 232 case 'grouped': 233 return __( $options = catcl_get_settings( 'grouped_button_text'), 'woocommerce' ); 234 break; 235 case 'external': 236 return __( $options = catcl_get_settings( 'external_button_text'), 'woocommerce' ); 237 break; 238 case 'variable': 239 return __( $options = catcl_get_settings( 'variable_button_text'), 'woocommerce' ); 240 break; 241 case 'booking': 242 return __( $options = catcl_get_settings( 'booking_button_text'), 'woocommerce-bookings' ); 243 break; 244 case 'subscription': 245 return __( $options = catcl_get_settings( 'subs_button_text'), 'woocommerce-subscriptions' ); 246 break; 247 case 'variable-subscription': 248 return __( $options = catcl_get_settings( 'subs_var_button_text'), 'woocommerce-subscriptions' ); 249 break; 250 251 default: 252 return __( 'Read more', 'woocommerce' ); 253 } 254 } 255 } 36 // Initialize the plugin. 37 add_action( 'plugins_loaded', 'wc_custom_atc_init' ); 38 function wc_custom_atc_init() { 39 WC_Custom_ATC_Admin::init(); 40 WC_Custom_ATC_Frontend::init(); 256 41 } 257 258 add_filter( 'woocommerce_get_settings_products','catcl_settings', 10, 2 );259 260 function catcl_get_settings( $key ) {261 $saved = get_option( $key );262 if( $saved && '' != $saved ) {263 return $saved;264 }265 return 'Add to cart';266 }
Note: See TracChangeset
for help on using the changeset viewer.