Plugin Directory

Changeset 2965611


Ignore:
Timestamp:
09/12/2023 04:03:24 AM (18 months ago)
Author:
jcwpplugins
Message:

New configuration option added to show quote button only on products that belong to a specific category

Location:
jcwp-add-quote-button-in-product-page
Files:
28 added
2 edited

Legend:

Unmodified
Added
Removed
  • jcwp-add-quote-button-in-product-page/trunk/jcwp-add-quote-button-in-product-page.php

    r2858684 r2965611  
    44* Plugin URI: https://jcwpplugins.com/jcwp-add-quote-button-in-product-page/
    55* Description: A plugin that adds a WhatsApp quote button on the WooCommerce product and shop page.
    6 * Version: 1.0.1
     6* Version: 1.0.2
    77* Author: JcwpPlugins
    88* Author URI: https://jcwpplugins.com
     
    8282                        <td><input type="text" name="jcwp_quote_option_field_message_text" value="<?php echo esc_attr( get_option('jcwp_quote_option_field_message_text') ); ?>" /></td>
    8383                    </tr>
     84                </table>
     85                <h1><?php echo __( 'Display Options', 'jcwp-add-quote-button-in-product-page' ); ?></h1>
     86                <table class="form-table">
    8487                    <tr valign="top">
    8588                        <th scope="row"><?php echo __( 'Show button on product page', 'jcwp-add-quote-button-in-product-page' ); ?></th>
     
    9194                    </tr>
    9295                </table>
     96                <table class="form-table" style="border: solid 1px #3313;padding: 10px;display: block;width: auto;">
     97                    <tr valign="top">
     98                        <th scope="row"><?php echo __( 'Show only in these categories:', 'jcwp-add-quote-button-in-product-page' ); ?></th>
     99                        <td><input type="text" placeholder="music,tshirts" name="jcwp_quote_option_field_show_on_categories" value="<?php echo esc_attr( get_option('jcwp_quote_option_field_show_on_categories') ); ?>" /></td>
     100                    </tr>
     101                </table>
     102                <pre style="margin: 0;padding:0;"><?php echo __( 'Add the slugs of the categories separated by comma', 'jcwp-add-quote-button-in-product-page' ); ?></pre>
     103
    93104                <?php submit_button(); ?>
    94105            </form>
     
    104115        register_setting( 'jcwp-quote-plugin-settings-group', 'jcwp_quote_option_field_show_on_product_page' );
    105116        register_setting( 'jcwp-quote-plugin-settings-group', 'jcwp_quote_option_field_show_on_shop_page' );
     117        register_setting( 'jcwp-quote-plugin-settings-group', 'jcwp_quote_option_field_show_on_categories' );
    106118    }
    107119
     
    112124        }
    113125        $quote_link = "https://wa.me/{$this->phone_number}?text=" . urlencode( "{$this->message_text} {$product->get_title()}: {$product->get_permalink()}" );
    114         ?>
    115         <a href="<?php echo esc_attr($quote_link); ?>" class="button jcwp-quote-button" target="_blank">
    116             <img src="<?php echo esc_attr($this->img_src); ?>">
    117             <?php echo esc_attr($this->button_text); ?>
    118         </a>
    119         <?php
     126        $category_slugs = wp_get_post_terms($product->get_id(), 'product_cat', array('fields' => 'slugs'));
     127        $show_categories = get_option('jcwp_quote_option_field_show_on_categories');
     128        $show_categories = str_replace(' ', '', $show_categories);
     129        if(!empty($show_categories)){
     130            $show_categories = explode(',', $show_categories);
     131            $common_elements = array_intersect($category_slugs, $show_categories);
     132            if(!empty($common_elements)){
     133                ?>
     134                <a href="<?php echo esc_attr($quote_link); ?>" class="button jcwp-quote-button" target="_blank">
     135                    <img src="<?php echo esc_attr($this->img_src); ?>">
     136                    <?php echo esc_attr($this->button_text); ?>
     137                </a>
     138                <?php
     139            }
     140        }else{
     141            ?>
     142            <a href="<?php echo esc_attr($quote_link); ?>" class="button jcwp-quote-button" target="_blank">
     143                <img src="<?php echo esc_attr($this->img_src); ?>">
     144                <?php echo esc_attr($this->button_text); ?>
     145            </a>
     146            <?php
     147        }
    120148    }
    121149
     
    126154        }
    127155        $quote_link = "https://wa.me/{$this->phone_number}?text=" . urlencode( "{$this->message_text} {$product->get_title()}: {$product->get_permalink()}" );
    128         ?>
    129         <a href="<?php echo esc_attr($quote_link); ?>" class="button jcwp-quote-button" target="_blank">
    130             <img src="<?php echo esc_attr($this->img_src); ?>">
    131             <?php echo esc_attr($this->button_text); ?>
    132         </a>
    133         <?php
     156        $category_slugs = wp_get_post_terms($product->get_id(), 'product_cat', array('fields' => 'slugs'));
     157        $show_categories = get_option( 'jcwp_quote_option_field_show_on_categories' );
     158        $show_categories = str_replace(' ', '', $show_categories);
     159        if(!empty($show_categories)){
     160            $show_categories = explode(',', $show_categories);
     161            $common_elements = array_intersect($category_slugs, $show_categories);
     162            if(!empty($common_elements)){
     163                ?>
     164                <a href="<?php echo esc_attr($quote_link); ?>" class="button jcwp-quote-button" target="_blank">
     165                    <img src="<?php echo esc_attr($this->img_src); ?>">
     166                    <?php echo esc_attr($this->button_text); ?>
     167                </a>
     168                <?php
     169            }
     170        }else{
     171            ?>
     172            <a href="<?php echo esc_attr($quote_link); ?>" class="button jcwp-quote-button" target="_blank">
     173                <img src="<?php echo esc_attr($this->img_src); ?>">
     174                <?php echo esc_attr($this->button_text); ?>
     175            </a>
     176            <?php
     177        }
    134178    }
    135179
  • jcwp-add-quote-button-in-product-page/trunk/readme.txt

    r2858684 r2965611  
    55Requires at least: 4.0
    66Tested up to: 6.1
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    44443. Button result on shop page
    45454. Button Result Example
     465. Show button only on products that belong to a specific category
    4647
    4748== Changelog ==
     49= 1.0.2 =
     50* New configuration option is added to show button only on products that belong to a specific category
    4851= 1.0.1 =
    4952* Add Settings link on plugins page
Note: See TracChangeset for help on using the changeset viewer.