Plugin Directory

Changeset 3275263


Ignore:
Timestamp:
04/17/2025 03:59:26 AM (12 months ago)
Author:
Kaira
Message:

Add prefix & suffix for variable products variations + other minor tweaks

Location:
woocustomizer
Files:
292 added
4 edited

Legend:

Unmodified
Added
Removed
  • woocustomizer/trunk/assets/css/frontend.css

    r2879214 r3275263  
    5151  border: 1px solid rgba(0, 0, 0, 0.3);
    5252  border-radius: 4px;
    53   box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5),
     53  box-shadow:
     54    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    5455    0 1px 4px rgba(0, 0, 0, 0.1);
    5556  text-decoration: none;
     
    216217.wcz-reviewsdiv-one.bot-divider,
    217218.wcz-addinfodiv-one.bot-divider {
    218   box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12), 0 1px 0 rgba(0, 0, 0, 0.12);
     219  box-shadow:
     220    0 -1px 0 rgba(0, 0, 0, 0.12),
     221    0 1px 0 rgba(0, 0, 0, 0.12);
    219222}
    220223
     
    656659}
    657660
    658 
     661.product .price small {
     662  opacity: 0.72;
     663}
     664
     665
  • woocustomizer/trunk/includes/inc/woocommerce.php

    r3229889 r3275263  
    967967    2
    968968);
     969// Add custom fields for each variation in the product edit screen
     970function wcz_add_variation_custom_fields(  $loop, $variation_data, $variation  ) {
     971    if ( !empty( get_option( 'wcz-add-price-prefix', woocustomizer_library_get_default( 'wcz-add-price-prefix' ) ) ) || empty( !get_option( 'wcz-add-price-suffix', woocustomizer_library_get_default( 'wcz-add-price-suffix' ) ) ) ) {
     972        woocommerce_wp_text_input( array(
     973            'id'            => 'wcz_prefix_field[' . $variation->ID . ']',
     974            'label'         => __( 'Variation Prefix', 'woocustomizer' ),
     975            'wrapper_class' => 'form-row form-row-first',
     976            'placeholder'   => __( '"& nbsp;" (without a space) to remove this prefix', 'woocustomizer' ),
     977            'desc_tip'      => true,
     978            'description'   => __( 'This will display before the variable price once a variation is selected.', 'woocustomizer' ),
     979            'value'         => get_post_meta( $variation->ID, 'wcz_var_price_prefix', true ),
     980        ) );
     981        woocommerce_wp_text_input( array(
     982            'id'            => 'wcz_suffix_field[' . $variation->ID . ']',
     983            'label'         => __( 'Variation Suffix', 'woocustomizer' ),
     984            'wrapper_class' => 'form-row form-row-last',
     985            'placeholder'   => __( '"& nbsp;" (without a space) to remove this suffix', 'woocustomizer' ),
     986            'desc_tip'      => true,
     987            'description'   => __( 'This will display after the variable price once a variation is selected.', 'woocustomizer' ),
     988            'value'         => get_post_meta( $variation->ID, 'wcz_var_price_suffix', true ),
     989        ) );
     990    }
     991}
     992
     993add_action(
     994    'woocommerce_variation_options_pricing',
     995    'wcz_add_variation_custom_fields',
     996    10,
     997    3
     998);
     999function wcz_save_variation_custom_fields(  $variation_id, $loop  ) {
     1000    if ( !empty( get_option( 'wcz-add-price-prefix', woocustomizer_library_get_default( 'wcz-add-price-prefix' ) ) ) || empty( !get_option( 'wcz-add-price-suffix', woocustomizer_library_get_default( 'wcz-add-price-suffix' ) ) ) ) {
     1001        // Save wcz_var_price_prefix
     1002        if ( isset( $_POST['wcz_prefix_field'][$variation_id] ) ) {
     1003            $prefix_field = sanitize_text_field( $_POST['wcz_prefix_field'][$variation_id] );
     1004            update_post_meta( $variation_id, 'wcz_var_price_prefix', $prefix_field );
     1005        }
     1006        // Save wcz_var_price_suffix
     1007        if ( isset( $_POST['wcz_suffix_field'][$variation_id] ) ) {
     1008            $suffix_field = sanitize_text_field( $_POST['wcz_suffix_field'][$variation_id] );
     1009            update_post_meta( $variation_id, 'wcz_var_price_suffix', $suffix_field );
     1010        }
     1011    }
     1012}
     1013
     1014add_action(
     1015    'woocommerce_save_product_variation',
     1016    'wcz_save_variation_custom_fields',
     1017    10,
     1018    2
     1019);
    9691020/**
    9701021 * ------------------------------------------------------------------------------------ WooCustomzer per Product settings.
     
    11661217
    11671218function wcz_add_price_prefix_suffix(  $price, $product  ) {
     1219    // If the product is a variation, attempt to get variation‐specific prefix/suffix.
     1220    if ( $product->is_type( 'variation' ) ) {
     1221        $variation_id = $product->get_id();
     1222        $var_prefix = ( get_post_meta( $variation_id, 'wcz_var_price_prefix', true ) ? '<small>' . get_post_meta( $variation_id, 'wcz_var_price_prefix', true ) . '</small> ' : '' );
     1223        $var_suffix = ( get_post_meta( $variation_id, 'wcz_var_price_suffix', true ) ? ' <small>' . get_post_meta( $variation_id, 'wcz_var_price_suffix', true ) . '</small>' : '' );
     1224        // If at least one is set, use them and return immediately.
     1225        if ( $var_prefix !== '' || $var_suffix !== '' ) {
     1226            return $var_prefix . $price . $var_suffix;
     1227        }
     1228    }
     1229    // Otherwise, for standard products (or variations without custom meta), use the global settings.
    11681230    $wcz_price_prefix = '';
    11691231    $wcz_price_suffix = '';
    11701232    if ( get_option( 'wcz-add-price-prefix', woocustomizer_library_get_default( 'wcz-add-price-prefix' ) ) ) {
    1171         if ( get_option( 'wcz-add-price-prefix-shop', woocustomizer_library_get_default( 'wcz-add-price-prefix-shop' ) ) && (is_shop() || is_product_category() || is_product_tag() || is_product() || is_cart()) ) {
    1172             $wcz_price_prefix = ( get_post_meta( get_the_ID(), 'wcz_pps_price_prefix', true ) ? '<small>' . get_post_meta( get_the_ID(), 'wcz_pps_price_prefix', true ) . '</small> ' : '<small>' . get_option( 'wcz-add-price-prefix-txt', woocustomizer_library_get_default( 'wcz-add-price-prefix-txt' ) ) . '</small> ' );
     1233        // Use the product-level meta if set; otherwise use the global default.
     1234        $prefix_meta = get_post_meta( get_the_ID(), 'wcz_pps_price_prefix', true );
     1235        if ( $prefix_meta ) {
     1236            $wcz_price_prefix = '<small>' . $prefix_meta . '</small> ';
    11731237        } else {
    1174             if ( is_product() ) {
    1175                 $wcz_price_prefix = ( get_post_meta( get_the_ID(), 'wcz_pps_price_prefix', true ) ? '<small>' . get_post_meta( get_the_ID(), 'wcz_pps_price_prefix', true ) . '</small> ' : '<small>' . get_option( 'wcz-add-price-prefix-txt', woocustomizer_library_get_default( 'wcz-add-price-prefix-txt' ) ) . '</small> ' );
    1176             }
     1238            $wcz_price_prefix = '<small>' . get_option( 'wcz-add-price-prefix-txt', woocustomizer_library_get_default( 'wcz-add-price-prefix-txt' ) ) . '</small> ';
    11771239        }
    11781240    }
    11791241    if ( get_option( 'wcz-add-price-suffix', woocustomizer_library_get_default( 'wcz-add-price-suffix' ) ) ) {
    1180         if ( get_option( 'wcz-add-price-suffix-shop', woocustomizer_library_get_default( 'wcz-add-price-suffix-shop' ) ) && (is_shop() || is_product_category() || is_product_tag() || is_product() || is_cart()) ) {
    1181             $wcz_price_suffix = ( get_post_meta( get_the_ID(), 'wcz_pps_price_suffix', true ) ? ' <small>' . get_post_meta( get_the_ID(), 'wcz_pps_price_suffix', true ) . '</small> ' : ' <small>' . get_option( 'wcz-add-price-suffix-txt', woocustomizer_library_get_default( 'wcz-add-price-suffix-txt' ) ) . '</small> ' );
     1242        $suffix_meta = get_post_meta( get_the_ID(), 'wcz_pps_price_suffix', true );
     1243        if ( $suffix_meta ) {
     1244            $wcz_price_suffix = ' <small>' . $suffix_meta . '</small> ';
    11821245        } else {
    1183             if ( is_product() ) {
    1184                 $wcz_price_suffix = ( get_post_meta( get_the_ID(), 'wcz_pps_price_suffix', true ) ? ' <small>' . get_post_meta( get_the_ID(), 'wcz_pps_price_suffix', true ) . '</small> ' : ' <small>' . get_option( 'wcz-add-price-suffix-txt', woocustomizer_library_get_default( 'wcz-add-price-suffix-txt' ) ) . '</small> ' );
    1185             }
    1186         }
    1187     }
     1246            $wcz_price_suffix = ' <small>' . get_option( 'wcz-add-price-suffix-txt', woocustomizer_library_get_default( 'wcz-add-price-suffix-txt' ) ) . '</small> ';
     1247        }
     1248    }
     1249    // Replace any tax placeholders if they are used.
    11881250    $price_excl_tax = wc_get_price_excluding_tax( $product );
    11891251    $price_incl_tax = wc_get_price_including_tax( $product );
     
    11921254    $wcz_price_suffix = str_ireplace( '{price_excluding_tax}', wc_price( $price_excl_tax ), $wcz_price_suffix );
    11931255    $wcz_price_suffix = str_ireplace( '{price_including_tax}', wc_price( $price_incl_tax ), $wcz_price_suffix );
    1194     $price = $wcz_price_prefix . $price . $wcz_price_suffix;
    1195     return $price;
     1256    // If the product is on sale and has separate sale HTML (<ins> tags), only add prefix/suffix inside the <ins> block.
     1257    if ( $product->is_on_sale() && strpos( $price, '<ins>' ) !== false ) {
     1258        if ( preg_match( '/(<ins>)(.*?)(<\\/ins>)/is', $price, $matches ) ) {
     1259            // The sale price is in $matches[2]
     1260            $new_sale = '<ins>' . $wcz_price_prefix . $matches[2] . $wcz_price_suffix . '</ins>';
     1261            // Replace the original <ins> block with our modified version.
     1262            $price = str_replace( $matches[0], $new_sale, $price );
     1263        }
     1264        return $price;
     1265    }
     1266    return $wcz_price_prefix . $price . $wcz_price_suffix;
    11961267}
    11971268
  • woocustomizer/trunk/readme.txt

    r3234446 r3275263  
    44Tags: customize woocommerce, ecommerce, woocommerce, online store, woocommerce addons
    55Requires at least: 5.0
    6 Tested up to: 6.7
     6Tested up to: 6.8
    77Requires PHP: 5.6
    8 Stable tag: 2.6.0
     8Stable tag: 2.6.1
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    180180
    181181
     182= Related Products by Kaira =
     183
     184[Blockons](https://wordpress.org/plugins/blockons/): Advanced editor blocks and site addons for your WordPress site.
     185
     186[Linkt](https://wordpress.org/plugins/linkt/): Affiliate and Custom link tracking and management.
     187
     188
    182189= Translations =
    183190
     
    261268
    262269== Changelog ==
     270
     271= 2.6.1 =
     272* Styling tweaks/fixes
     273* Minor code refactoring
     274* Added: Price Prefix & Suffix for variable product variations
     275* Updated the language .pot file
    263276
    264277= 2.6.0 =
  • woocustomizer/trunk/woocustomizer.php

    r3234446 r3275263  
    33/**
    44 * Plugin Name: StoreCustomizer
    5  * Version: 2.6.0
     5 * Version: 2.6.1
    66 * Plugin URI: https://kairaweb.com/wordpress-plugins/woocustomizer/
    77 * Description: A store editor plugin for editing all WooCommerce store and product pages, cart, checkout and user account pages, all within the WordPress Customizer
     
    99 * Author URI: https://kairaweb.com/
    1010 * Requires at least: 5.0
    11  * Tested up to: 6.7
     11 * Tested up to: 6.8
    1212 * WC requires at least: 3.2
    13  * WC tested up to: 9.6
     13 * WC tested up to: 9.8
    1414 * Text Domain: woocustomizer
    1515 * Domain Path: /lang/
     
    2020 * @since 1.0.0
    2121 */
    22 define( 'WCD_PLUGIN_VERSION', '2.6.0' );
     22define( 'WCD_PLUGIN_VERSION', '2.6.1' );
    2323define( 'WCD_PLUGIN_URL', plugins_url( '', __FILE__ ) );
    2424if ( !defined( 'ABSPATH' ) ) {
Note: See TracChangeset for help on using the changeset viewer.