Plugin Directory

Changeset 3811305


Ignore:
Timestamp:
11/19/2026 11:03:54 AM (18 hours ago)
Author:
hamzaafridi05
Message:

Version 1.0.4: Quote only for single products

A product can now be set to Quote only in its Quote settings box. The quote button then replaces Add to Cart for that product alone: it cannot be bought from the product page, the shop page, a direct link or the Store API, and with Hide the price on its price is hidden too, while the rest of the shop keeps Add to Cart. Also fixed: on block themes with WooCommerce 11.3 a hidden price could still be read in the page's product data, and saving a guest's quote in the admin made the shop owner its customer. Tested with WordPress 7.1 and WooCommerce 11.3.

Location:
devtonic-quote-requests-for-woocommerce
Files:
82 added
10 edited

Legend:

Unmodified
Added
Removed
  • devtonic-quote-requests-for-woocommerce/trunk/devtonic-quote-requests-for-woocommerce.php

    r3751148 r3811305  
    44 * Plugin URI:            https://devtonicstudios.com/quotewise
    55 * Description:           Request a Quote for WooCommerce. Every quote on one screen, accept or decline in one click, with status history and internal notes.
    6  * Version:               1.0.3
     6 * Version:               1.0.4
    77 * Author:                Devtonic Studios
    88 * Author URI:            https://devtonicstudios.com
    … …  
    1616 * Requires Plugins:      woocommerce
    1717 * WC requires at least:  7.0
    18  * WC tested up to:       11.1
     18 * WC tested up to:       11.3
    1919 *
    2020 * @package Quote Requests
    … …  
    2525}
    2626
    27 define( 'DEVTONIC_QR_VERSION',     '1.0.3' );
     27define( 'DEVTONIC_QR_VERSION',     '1.0.4' );
    2828define( 'DEVTONIC_QR_PLUGIN_FILE', __FILE__ );
    2929define( 'DEVTONIC_QR_PLUGIN_DIR',  plugin_dir_path( __FILE__ ) );
  • devtonic-quote-requests-for-woocommerce/trunk/includes/admin/class-devtonic-qr-admin-product-meta.php

    r3656027 r3811305  
    6161                <p>
    6262                        <label>
     63                                <input type="radio" name="quotewise_product_mode" value="quote_only" <?php checked( $mode, 'quote_only' ); ?> />
     64                                <?php esc_html_e( 'Quote only: the quote button replaces Add to Cart', 'devtonic-quote-requests-for-woocommerce' ); ?>
     65                        </label>
     66                </p>
     67                <p>
     68                        <label>
    6369                                <input type="radio" name="quotewise_product_mode" value="force_off" <?php checked( $mode, 'force_off' ); ?> />
    6470                                <?php esc_html_e( 'Force quote button OFF for this product', 'devtonic-quote-requests-for-woocommerce' ); ?>
    … …  
    6773                <p class="description">
    6874                        <?php esc_html_e( '"Use shop default" follows the global Quote mode setting.', 'devtonic-quote-requests-for-woocommerce' ); ?>
     75                </p>
     76                <p class="description">
     77                        <?php esc_html_e( '"Quote only" sells this product through quotes only, even when the rest of the shop keeps Add to Cart. It cannot be bought from the product page, the shop page or a direct add-to-cart link. With "Hide the price" on (Quotes > Settings > Display), its price is hidden too.', 'devtonic-quote-requests-for-woocommerce' ); ?>
    6978                </p>
    7079                <?php
    … …  
    8998
    9099                $mode = isset( $_POST['quotewise_product_mode'] ) ? sanitize_key( wp_unslash( $_POST['quotewise_product_mode'] ) ) : 'default';
    91                 if ( ! in_array( $mode, array( 'default', 'force_on', 'force_off' ), true ) ) {
     100                if ( ! in_array( $mode, quotewise_product_modes(), true ) ) {
    92101                        $mode = 'default';
    93102                }
  • devtonic-quote-requests-for-woocommerce/trunk/includes/admin/class-devtonic-qr-admin-settings.php

    r3712211 r3811305  
    533533                                                </fieldset>
    534534                                                <p class="description">
    535                                                         <?php esc_html_e( 'Each product page also has its own override box (Force ON / Force OFF / Use shop default).', 'devtonic-quote-requests-for-woocommerce' ); ?>
     535                                                        <?php esc_html_e( 'Each product page also has its own override box (Use shop default / Force ON / Quote only / Force OFF). Quote only makes that one product quote-only while the rest of the shop keeps Add to Cart.', 'devtonic-quote-requests-for-woocommerce' ); ?>
    536536                                                </p>
    537537                                        </td>
    … …  
    719719                                                <p class="description">
    720720                                                        <?php esc_html_e( 'Replace makes these products quote-only: they cannot be bought from the product page, the shop page or a direct add-to-cart link.', 'devtonic-quote-requests-for-woocommerce' ); ?>
     721                                                        <?php esc_html_e( 'To make only some products quote-only, keep "Show alongside Add to Cart" and choose "Quote only" in the Quote settings box of each of those products.', 'devtonic-quote-requests-for-woocommerce' ); ?>
    721722                                                </p>
    722723                                        </td>
    … …  
    730731                                                </label>
    731732                                                <p class="description">
    732                                                         <?php esc_html_e( 'Works with "Replace Add to Cart". The price is left out of the product page, the shop page, the quote basket, the product data Google reads, and WooCommerce\'s public product API. You still see it here in the admin.', 'devtonic-quote-requests-for-woocommerce' ); ?>
     733                                                        <?php esc_html_e( 'Works on quote-only products: all of them with "Replace Add to Cart", or the products set to "Quote only" on their own product page. The price is left out of the product page, the shop page, the quote basket, the product data Google reads, and WooCommerce\'s public product API. You still see it here in the admin.', 'devtonic-quote-requests-for-woocommerce' ); ?>
    733734                                                </p>
    734735                                        </td>
  • devtonic-quote-requests-for-woocommerce/trunk/includes/class-devtonic-qr-post-types.php

    r3656027 r3811305  
    2020                add_action( 'current_screen', array( __CLASS__, 'restrict_screen_for_non_managers' ) );
    2121                add_filter( 'wp_insert_post_data', array( __CLASS__, 'guard_status_against_core_buttons' ), 10, 2 );
     22                add_filter( 'wp_insert_post_data', array( __CLASS__, 'keep_quote_author' ), 10, 2 );
    2223                add_filter( 'wp_untrash_post_status', array( __CLASS__, 'restore_status_on_untrash' ), 10, 3 );
    2324        }
    … …  
    6263                if ( $current && 0 === strpos( $current, 'quotewise-' ) ) {
    6364                        $data['post_status'] = $current;
     65                }
     66                return $data;
     67        }
     68
     69        /**
     70         * A quote belongs to the customer who asked for it, or to nobody when a guest asked. WordPress
     71         * gives a post with no author to whoever saves it next (the edit screen sends the current user),
     72         * so saving a guest's quote made the shop owner its customer. Once a quote exists, its author
     73         * never changes.
     74         *
     75         * @param array $data    Slashed, sanitized post data about to be written.
     76         * @param array $postarr Raw post array (includes ID on updates).
     77         * @return array
     78         */
     79        public static function keep_quote_author( $data, $postarr ) {
     80                if ( ! isset( $data['post_type'] ) || self::POST_TYPE !== $data['post_type'] || empty( $postarr['ID'] ) ) {
     81                        return $data;
     82                }
     83                $stored = get_post_field( 'post_author', (int) $postarr['ID'], 'raw' );
     84                if ( is_numeric( $stored ) ) {
     85                        $data['post_author'] = (int) $stored;
    6486                }
    6587                return $data;
  • devtonic-quote-requests-for-woocommerce/trunk/includes/class-devtonic-qr-price-visibility.php

    r3712211 r3811305  
    1010 *
    1111 * With "Hide the price" on, the price is also left out of the page, the variation data,
    12  * the product data Google reads (JSON-LD) and WooCommerce's public Store API.
     12 * the product data Google reads (JSON-LD), WooCommerce's public Store API, and the Store API
     13 * copies that WooCommerce's product blocks print into a block theme's page.
    1314 *
    1415 * @package Quote Requests
    … …  
    3334                add_filter( 'woocommerce_structured_data_product', array( __CLASS__, 'structured_data' ), 100, 2 );
    3435                add_filter( 'rest_post_dispatch', array( __CLASS__, 'store_api_response' ), 100, 3 );
     36                // Block themes: WooCommerce (11.3 and later) loads Store API data for the products on the page
     37                // straight from the Store API code, past rest_post_dispatch, and prints it as the page's
     38                // interactivity state.
     39                add_filter( 'script_module_data_@wordpress/interactivity', array( __CLASS__, 'interactivity_data' ), 100 );
    3540        }
    3641
    … …  
    181186                $items  = $single ? array( $data ) : $data;
    182187                foreach ( $items as $i => $item ) {
    183                         if ( ! is_array( $item ) || empty( $item['id'] ) ) {
     188                        $items[ $i ] = self::store_api_item( $item );
     189                }
     190                $response->set_data( $single ? $items[0] : $items );
     191                return $response;
     192        }
     193
     194        /**
     195         * The product data WooCommerce's product blocks print into a block theme's page: the same
     196         * Store API data, so it gets the same treatment as the public Store API.
     197         *
     198         * @param array $data Data for the @wordpress/interactivity script module.
     199         * @return array
     200         */
     201        public static function interactivity_data( $data ) {
     202                if ( self::is_admin_screen() || ! is_array( $data ) || empty( $data['state']['woocommerce/products'] ) || ! is_array( $data['state']['woocommerce/products'] ) ) {
     203                        return $data;
     204                }
     205                foreach ( array( 'products', 'productVariations' ) as $group ) {
     206                        if ( empty( $data['state']['woocommerce/products'][ $group ] ) || ! is_array( $data['state']['woocommerce/products'][ $group ] ) ) {
    184207                                continue;
    185208                        }
    186                         $product = wc_get_product( (int) $item['id'] );
    187                         if ( ! $product || ! quotewise_is_quote_only( $product ) ) {
    188                                 continue;
     209                        foreach ( $data['state']['woocommerce/products'][ $group ] as $id => $item ) {
     210                                $data['state']['woocommerce/products'][ $group ][ $id ] = self::store_api_item( $item );
    189211                        }
    190                         $item['is_purchasable'] = false;
    191                         // The Store API hands nested parts over as objects, not arrays.
    192                         if ( isset( $item['add_to_cart'] ) ) {
    193                                 $text = quotewise_get_setting( 'button_text', 'Request a Quote' );
    194                                 self::set_fields(
    195                                         $item['add_to_cart'],
    196                                         array(
    197                                                 'text'        => $text,
    198                                                 'single_text' => $text,
    199                                                 'url'         => $product->get_permalink(),
    200                                         )
    201                                 );
    202                         }
    203                         if ( quotewise_price_is_hidden( $product ) && isset( $item['prices'] ) ) {
    204                                 self::set_fields(
    205                                         $item['prices'],
    206                                         array(
    207                                                 'price'         => '',
    208                                                 'regular_price' => '',
    209                                                 'sale_price'    => '',
    210                                                 'price_range'   => null,
    211                                         )
    212                                 );
    213                                 $item['price_html'] = quotewise_hidden_price_html( $product );
    214                         }
    215                         $items[ $i ] = $item;
    216                 }
    217                 $response->set_data( $single ? $items[0] : $items );
    218                 return $response;
     212                }
     213                return $data;
     214        }
     215
     216        /**
     217         * One product in Store API format: a quote-only product is marked as not purchasable, and a
     218         * hidden price is removed.
     219         *
     220         * @param mixed $item Product data (an array; its nested parts can be objects).
     221         * @return mixed
     222         */
     223        private static function store_api_item( $item ) {
     224                if ( ! is_array( $item ) || empty( $item['id'] ) ) {
     225                        return $item;
     226                }
     227                $product = wc_get_product( (int) $item['id'] );
     228                if ( ! $product || ! quotewise_is_quote_only( $product ) ) {
     229                        return $item;
     230                }
     231                $item['is_purchasable'] = false;
     232                // The Store API hands nested parts over as objects, not arrays.
     233                if ( isset( $item['add_to_cart'] ) ) {
     234                        $text = quotewise_get_setting( 'button_text', 'Request a Quote' );
     235                        self::set_fields(
     236                                $item['add_to_cart'],
     237                                array(
     238                                        'text'        => $text,
     239                                        'single_text' => $text,
     240                                        'url'         => $product->get_permalink(),
     241                                )
     242                        );
     243                }
     244                if ( quotewise_price_is_hidden( $product ) && isset( $item['prices'] ) ) {
     245                        self::set_fields(
     246                                $item['prices'],
     247                                array(
     248                                        'price'         => '',
     249                                        'regular_price' => '',
     250                                        'sale_price'    => '',
     251                                        'price_range'   => null,
     252                                )
     253                        );
     254                        $item['price_html'] = quotewise_hidden_price_html( $product );
     255                }
     256                return $item;
    219257        }
    220258
  • devtonic-quote-requests-for-woocommerce/trunk/includes/frontend/class-devtonic-qr-button.php

    r3712211 r3811305  
    109109                $text      = apply_filters( 'quotewise_button_text', $settings['button_text'], $product );
    110110                $color     = $settings['button_color'];
    111                 $placement = $settings['button_placement'];
     111                // Per product: a "Quote only" product replaces Add to Cart even when the shop setting says alongside.
     112                $placement = quotewise_is_quote_only( $product ) ? 'replace' : 'alongside';
    112113
    113114                $template_args = array(
  • devtonic-quote-requests-for-woocommerce/trunk/includes/helpers/functions-devtonic-qr.php

    r3751148 r3811305  
    7272}
    7373
     74if ( ! function_exists( 'quotewise_product_modes' ) ) {
     75        /**
     76         * The choices in a product's Quote settings box.
     77         *
     78         * - default:    follows the shop's Quote mode and Button placement.
     79         * - force_on:   the quote button always shows; Button placement decides whether it sits next
     80         *               to Add to Cart or replaces it.
     81         * - quote_only: the quote button always shows and replaces Add to Cart, so the product is
     82         *               never sold through the cart, whatever Button placement says for the rest of the shop.
     83         * - force_off:  the quote button never shows.
     84         *
     85         * @return string[]
     86         */
     87        function quotewise_product_modes() {
     88                return array( 'default', 'force_on', 'quote_only', 'force_off' );
     89        }
     90}
     91
    7492if ( ! function_exists( 'quotewise_get_product_mode' ) ) {
    7593        function quotewise_get_product_mode( $product_id ) {
    7694                $value = get_post_meta( $product_id, '_quotewise_product_mode', true );
    77                 if ( ! in_array( $value, array( 'default', 'force_on', 'force_off' ), true ) ) {
     95                if ( ! in_array( $value, quotewise_product_modes(), true ) ) {
    7896                        $value = 'default';
    7997                }
    … …  
    93111                        return apply_filters( 'quotewise_button_visible', false, $product );
    94112                }
    95                 if ( 'force_on' === $product_mode ) {
     113                if ( 'force_on' === $product_mode || 'quote_only' === $product_mode ) {
    96114                        return apply_filters( 'quotewise_button_visible', true, $product );
    97115                }
    … …  
    129147        /**
    130148         * Quote-only: the Add to Quote button shows and replaces Add to Cart, so the product
    131          * is never sold through the cart. The Pro version adds its per-role rules here.
     149         * is never sold through the cart. That is every product with the button when Button
     150         * placement is "Replace Add to Cart", or one product set to "Quote only" in its Quote
     151         * settings box while the rest of the shop keeps Add to Cart. The Pro version adds its
     152         * per-role rules here.
    132153         *
    133154         * @param WC_Product|int $product Product or product ID.
    … …  
    139160                        return false;
    140161                }
    141                 $quote_only = 'replace' === quotewise_get_setting( 'button_placement', 'alongside' ) && quotewise_button_should_show( $product );
     162                $replaces = 'replace' === quotewise_get_setting( 'button_placement', 'alongside' )
     163                        || 'quote_only' === quotewise_get_product_mode( $product->get_id() );
     164                // Only while the quote button shows: a product with neither button could not be bought or quoted.
     165                $quote_only = $replaces && quotewise_button_should_show( $product );
    142166                return (bool) apply_filters( 'quotewise_is_quote_only', $quote_only, $product );
    143167        }
  • devtonic-quote-requests-for-woocommerce/trunk/languages/devtonic-quote-requests-for-woocommerce.pot

    r3656027 r3811305  
    9090msgstr ""
    9191
     92msgid "Quote only: the quote button replaces Add to Cart"
     93msgstr ""
     94
    9295msgid "Force quote button OFF for this product"
     96msgstr ""
     97
     98msgid "\"Quote only\" sells this product through quotes only, even when the rest of the shop keeps Add to Cart. It cannot be bought from the product page, the shop page or a direct add-to-cart link. With \"Hide the price\" on (Quotes > Settings > Display), its price is hidden too."
    9399msgstr ""
    94100
  • devtonic-quote-requests-for-woocommerce/trunk/readme.txt

    r3751148 r3811305  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.0.3
     7Stable tag: 1.0.4
    88WC requires at least: 7.0
    9 WC tested up to: 11.1
     9WC tested up to: 11.3
    1010License: GPLv2 or later
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    2626
    2727* Add to Quote button on product pages, next to Add to Cart or in place of it
    28 * Per-product control: force the button on, force it off, or follow the shop default
     28* Per-product control: force the button on, force it off, follow the shop default, or make just that product quote only while the rest of the shop keeps Add to Cart
    2929* Change the button text, color, and position
    3030* Session-based quote basket, kept separate from the normal WooCommerce cart
    … …  
    4242* Works for guests too, no account needed to request a quote
    4343* HPOS (High-Performance Order Storage) compatible
    44 * Translation-ready (text domain: quotewise)
     44* Translation-ready (text domain: devtonic-quote-requests-for-woocommerce)
    4545
    4646The free version manages quotes end to end. It does not turn an accepted quote into a paid order. Taking the payment is the job of the Pro version, below.
    … …  
    7373== Installation ==
    7474
    75 1. Upload the `quotewise` folder to `/wp-content/plugins/`, or install through the Plugins screen in WordPress.
     751. Upload the `devtonic-quote-requests-for-woocommerce` folder to `/wp-content/plugins/`, or install through the Plugins screen in WordPress.
    76762. Activate the plugin through the Plugins screen.
    77773. Make sure WooCommerce is also installed and active.
    … …  
    9292
    9393In the WooCommerce session, the same place as the normal cart. It does not mix into the regular cart, and it is not saved to the database until the customer submits the quote.
     94
     95= Can I make only some products quote only? =
     96
     97Yes. Keep Button placement on "Show alongside Add to Cart" under **Quotes → Settings → Display**. Then open each product that should be quote only and choose "Quote only" in its Quote settings box. Those products lose Add to Cart and cannot be bought from the product page, the shop page or a direct add-to-cart link, while every other product sells as normal. Turn on "Hide the price" to show your own text, such as "Price on request", in place of their price.
    9498
    9599= Can a guest customer (not logged in) submit a quote? =
    … …  
    145149
    146150== Changelog ==
     151
     152= 1.0.4 =
     153* New: Quote only for single products. Choose "Quote only" in a product's Quote settings box and that product is sold through quotes only: no Add to Cart on the product page or the shop page, and no way to buy it with a direct link or through the Store API, while the rest of the shop keeps Add to Cart. With "Hide the price" on, its price is hidden too. Until now quote only was one setting for the whole shop. Thanks to Rodger Firmin for the idea.
     154* Fixed: on block themes with WooCommerce 11.3, the price of a quote-only product with "Hide the price" on could still be read in the page's hidden data, where WooCommerce's product blocks keep the products they show. It is left out there too now.
     155* Fixed: saving a guest's quote on its admin screen made the shop owner the customer of that quote. A quote now keeps its customer, or none when a guest asked.
     156* Tested with WordPress 7.1 and WooCommerce 11.3.
    147157
    148158= 1.0.3 =
    … …  
    179189== Upgrade Notice ==
    180190
     191= 1.0.4 =
     192Adds Quote only for single products, so a shop can sell most products as normal and keep a few on quote only. Your quotes and settings are untouched.
     193
    181194= 1.0.3 =
    182195Quote lines now show what the customer chose, and a product priced by a calculator such as PriceWise is quoted at that price. Your quotes and settings are untouched.
  • devtonic-quote-requests-for-woocommerce/trunk/templates/single-product/add-to-quote-button.php

    r3656027 r3811305  
    1919// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- Template variables are provided by wc_get_template() $args (function-scoped, not globals); WooCommerce email header/footer hooks are invoked intentionally.
    2020
    21 // When $placement is "replace", the Add to Cart button is hidden by the
    22 // .quotewise-replace-add-to-cart body class (see assets/css/devtonic-qr-frontend.css).
     21// When $placement is "replace" (the product is quote-only, for the whole shop or this product
     22// alone), the Add to Cart button is hidden by the .quotewise-replace-add-to-cart body class
     23// (see assets/css/devtonic-qr-frontend.css).
    2324?>
    2425<span class="quotewise-button-wrap">
Note: See TracChangeset for help on using the changeset viewer.