Plugin Directory

Changeset 2042986


Ignore:
Timestamp:
03/02/2019 11:06:09 PM (6 years ago)
Author:
cmachu
Message:

Version 1.1.0 - see changelog

Location:
multiple-external-product-urls-for-woocommerce
Files:
11 edited
1 copied

Legend:

Unmodified
Added
Removed
  • multiple-external-product-urls-for-woocommerce/tags/1.1.0/README.txt

    r1933588 r2042986  
    44Tags: woocommerce, external product, woo, external, product, product url
    55Requires at least: 3.0.1
    6 Tested up to: 4.9.8
    7 Stable tag: 1.0.0
     6Tested up to: 5.1
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535== Changelog ==
    3636
     37= 1.1.0 =
     38* ADD: Ability to switch on/off displaying additional external product buttons on category loops
     39* FIX: JS error with single quotes on button labels
     40* FIX: Common fixes
     41
     42
    3743= 1.0.0 =
    3844* Initial release
  • multiple-external-product-urls-for-woocommerce/tags/1.1.0/admin/class-mepu-woo-additional-fields.php

    r1933588 r2042986  
    7878            $multiple_external_fields = array();
    7979        }
    80         echo "<input type='hidden' value='".json_encode($multiple_external_fields)."' id='mepu-woo-data'>";
     80        echo "<input type='hidden' value='".json_encode($multiple_external_fields, JSON_HEX_APOS)."' id='mepu-woo-data'>";
    8181
    8282    ?>
     
    8989                    'label'       => __( 'Open in new tab', 'mepu-woo' ),
    9090                    'description' => __('Open external / affiliate URLs in new tab?', 'mepu-woo')
     91                )
     92            );
     93
     94            woocommerce_wp_checkbox(
     95                array(
     96                    'id'          => '_external_show_in_cat',
     97                    'label'       => __( 'Category pages', 'mepu-woo' ),
     98                    'description' => __('Show all external product buttons on category pages', 'mepu-woo')
    9199                )
    92100            );
     
    129137        $fine_array = array();
    130138
    131         if ( ! ( isset( $_POST['woocommerce_meta_nonce'], $_POST[ '_external_target_blank' ], $_POST[ '_product_url_' ], $_POST[ '_button_text_' ] ) || wp_verify_nonce( sanitize_key( $_POST['woocommerce_meta_nonce'] ), 'woocommerce_save_data' ) ) ) {
     139        if ( ! ( isset( $_POST['woocommerce_meta_nonce'], $_POST[ '_external_target_blank' ], $_POST[ '_product_url_' ], $_POST[ '_button_text_' ] )
     140            || wp_verify_nonce( sanitize_key( $_POST['woocommerce_meta_nonce'] ), 'woocommerce_save_data' ) ) ) {
    132141            return false;
    133142        }
     
    153162        );
    154163
     164        update_post_meta(
     165            $post_id,
     166            '_external_show_in_cat',
     167            esc_attr($_POST['_external_show_in_cat'])
     168        );
     169
    155170    }
    156171
  • multiple-external-product-urls-for-woocommerce/tags/1.1.0/frontend/class-mepu-woo-frontend.php

    r1933588 r2042986  
    5959     * Render all buttons to external shops on product page
    6060     * @since   1.0.0
    61      * @param   int  $product_id ID of product
    6261     */
    6362    public function render_mepu_buttons()
    6463    {
    6564        global $product;
    66         if($product) {
    67             if ($product->get_type() == 'external') {
    68                 $mepu_data = get_post_meta($product->get_id(),'_multiple_external_');
    69                 if(is_array($mepu_data[0])){
    70                     foreach($mepu_data[0] as $mepu_item){
    71                         ?>
    72                         <form class="cart" action="<?php echo esc_url( $mepu_item[0] ); ?>" method="get">
    73                             <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
     65        if ($product && ('external' == $product->get_type())) {
     66            $mepu_data = get_post_meta($product->get_id(), '_multiple_external_');
     67            if (is_array($mepu_data[0])) {
     68                foreach ($mepu_data[0] as $mepu_item) {
     69                    ?>
     70                    <form class="cart" action="<?php echo esc_url($mepu_item[0]); ?>" method="get">
     71                        <?php do_action('woocommerce_before_add_to_cart_button'); ?>
    7472
    75                             <button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $mepu_item[1] ); ?></button>
     73                        <button type="submit"
     74                                class="single_add_to_cart_button button alt"><?php echo esc_html($mepu_item[1]); ?></button>
    7675
    77                             <?php wc_query_string_form_fields( $mepu_item[0] ); ?>
     76                        <?php wc_query_string_form_fields($mepu_item[0]); ?>
    7877
    79                             <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
    80                         </form>
    81                         <?php
    82                     }
     78                        <?php do_action('woocommerce_after_add_to_cart_button'); ?>
     79                    </form>
     80                    <?php
    8381                }
    8482            }
     
    8785
    8886    /**
     87     * Add multiple external buttons to loop in category
     88     * @since   1.1.0
     89     * @param $buttons
     90     * @param $product
     91     * @param $args
     92     * @return string
     93     */
     94    public function render_mepu_buttons_loop($buttons, $product, $args)
     95    {
     96        if (get_post_meta($product->get_id(), '_external_show_in_cat', true) && ('external' == $product->get_type())) {
     97            $mepu_data = get_post_meta($product->get_id(), '_multiple_external_');
     98            if (is_array($mepu_data[0])) {
     99                foreach ($mepu_data[0] as $mepu_item) {
     100                    $buttons .= sprintf('<a href="%s" data-quantity="%s" class="%s" %s>%s</a>',
     101                        esc_url($mepu_item[0]),
     102                        esc_attr(isset($args['quantity']) ? $args['quantity'] : 1),
     103                        esc_attr(isset($args['class']) ? $args['class'] : 'button'),
     104                        isset($args['attributes']) ? wc_implode_html_attributes($args['attributes']) : '',
     105                        esc_html($mepu_item[1]));
     106                }
     107            }
     108        }
     109
     110        return $buttons;
     111    }
     112
     113    /**
    89114     * Adjust cart form details
    90115     * @since   1.0.0
    91      * @param   int  $product_id ID of product
    92116     */
    93117    public function adjust_cart_form_details()
    94118    {
    95119        global $product;
    96         if($product) {
     120        if ($product) {
    97121            if ($product->get_type() == 'external') {
    98122                $mepu_data = get_post_meta($product->get_id(), '_external_target_blank', true);
     
    100124                    ?>
    101125                    <script>
    102                         if (jQuery('.cart')){
    103                             jQuery('.cart').attr('target','_blank');
     126                        if (jQuery('.cart')) {
     127                            jQuery('.cart').attr('target', '_blank');
    104128                        }
    105129                    </script>
     
    110134    }
    111135
     136    /**
     137     * Adjust external product buttons on category loop
     138     * @since   1.1.0
     139     * @param $args
     140     * @param $product
     141     * @return mixed
     142     */
     143    public function adjust_cart_form_details_loop($args, $product)
     144    {
     145        if (get_post_meta($product->get_id(), '_external_show_in_cat', true) && get_post_meta($product->get_id(), '_external_target_blank', true)) {
     146            $args['attributes']['target'] = '_blank';
     147        }
     148
     149        return $args;
     150    }
     151
    112152}
  • multiple-external-product-urls-for-woocommerce/tags/1.1.0/includes/class-mepu-woo.php

    r1933588 r2042986  
    179179        $this->loader->add_action('woocommerce_after_add_to_cart_form', $plugin, 'render_mepu_buttons');
    180180        $this->loader->add_action('woocommerce_after_add_to_cart_form', $plugin, 'adjust_cart_form_details');
     181
     182        $this->loader->add_filter('woocommerce_loop_add_to_cart_link', $plugin, 'render_mepu_buttons_loop', 10, 3);
     183        $this->loader->add_filter('woocommerce_loop_add_to_cart_args', $plugin, 'adjust_cart_form_details_loop', 10, 3);
    181184    }
    182185
  • multiple-external-product-urls-for-woocommerce/tags/1.1.0/mepu-woo.php

    r1933588 r2042986  
    2828 * Rename this for your plugin and update it as you release new versions.
    2929 */
    30 define('MEPU_WOO_VERSION', '1.0.0');
     30define('MEPU_WOO_VERSION', '1.1.0');
    3131
    3232/**
  • multiple-external-product-urls-for-woocommerce/trunk/README.txt

    r1933588 r2042986  
    44Tags: woocommerce, external product, woo, external, product, product url
    55Requires at least: 3.0.1
    6 Tested up to: 4.9.8
    7 Stable tag: 1.0.0
     6Tested up to: 5.1
     7Stable tag: 1.1.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535== Changelog ==
    3636
     37= 1.1.0 =
     38* ADD: Ability to switch on/off displaying additional external product buttons on category loops
     39* FIX: JS error with single quotes on button labels
     40* FIX: Common fixes
     41
     42
    3743= 1.0.0 =
    3844* Initial release
  • multiple-external-product-urls-for-woocommerce/trunk/admin/class-mepu-woo-additional-fields.php

    r1933588 r2042986  
    7878            $multiple_external_fields = array();
    7979        }
    80         echo "<input type='hidden' value='".json_encode($multiple_external_fields)."' id='mepu-woo-data'>";
     80        echo "<input type='hidden' value='".json_encode($multiple_external_fields, JSON_HEX_APOS)."' id='mepu-woo-data'>";
    8181
    8282    ?>
     
    8989                    'label'       => __( 'Open in new tab', 'mepu-woo' ),
    9090                    'description' => __('Open external / affiliate URLs in new tab?', 'mepu-woo')
     91                )
     92            );
     93
     94            woocommerce_wp_checkbox(
     95                array(
     96                    'id'          => '_external_show_in_cat',
     97                    'label'       => __( 'Category pages', 'mepu-woo' ),
     98                    'description' => __('Show all external product buttons on category pages', 'mepu-woo')
    9199                )
    92100            );
     
    129137        $fine_array = array();
    130138
    131         if ( ! ( isset( $_POST['woocommerce_meta_nonce'], $_POST[ '_external_target_blank' ], $_POST[ '_product_url_' ], $_POST[ '_button_text_' ] ) || wp_verify_nonce( sanitize_key( $_POST['woocommerce_meta_nonce'] ), 'woocommerce_save_data' ) ) ) {
     139        if ( ! ( isset( $_POST['woocommerce_meta_nonce'], $_POST[ '_external_target_blank' ], $_POST[ '_product_url_' ], $_POST[ '_button_text_' ] )
     140            || wp_verify_nonce( sanitize_key( $_POST['woocommerce_meta_nonce'] ), 'woocommerce_save_data' ) ) ) {
    132141            return false;
    133142        }
     
    153162        );
    154163
     164        update_post_meta(
     165            $post_id,
     166            '_external_show_in_cat',
     167            esc_attr($_POST['_external_show_in_cat'])
     168        );
     169
    155170    }
    156171
  • multiple-external-product-urls-for-woocommerce/trunk/frontend/class-mepu-woo-frontend.php

    r1933588 r2042986  
    5959     * Render all buttons to external shops on product page
    6060     * @since   1.0.0
    61      * @param   int  $product_id ID of product
    6261     */
    6362    public function render_mepu_buttons()
    6463    {
    6564        global $product;
    66         if($product) {
    67             if ($product->get_type() == 'external') {
    68                 $mepu_data = get_post_meta($product->get_id(),'_multiple_external_');
    69                 if(is_array($mepu_data[0])){
    70                     foreach($mepu_data[0] as $mepu_item){
    71                         ?>
    72                         <form class="cart" action="<?php echo esc_url( $mepu_item[0] ); ?>" method="get">
    73                             <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
     65        if ($product && ('external' == $product->get_type())) {
     66            $mepu_data = get_post_meta($product->get_id(), '_multiple_external_');
     67            if (is_array($mepu_data[0])) {
     68                foreach ($mepu_data[0] as $mepu_item) {
     69                    ?>
     70                    <form class="cart" action="<?php echo esc_url($mepu_item[0]); ?>" method="get">
     71                        <?php do_action('woocommerce_before_add_to_cart_button'); ?>
    7472
    75                             <button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $mepu_item[1] ); ?></button>
     73                        <button type="submit"
     74                                class="single_add_to_cart_button button alt"><?php echo esc_html($mepu_item[1]); ?></button>
    7675
    77                             <?php wc_query_string_form_fields( $mepu_item[0] ); ?>
     76                        <?php wc_query_string_form_fields($mepu_item[0]); ?>
    7877
    79                             <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
    80                         </form>
    81                         <?php
    82                     }
     78                        <?php do_action('woocommerce_after_add_to_cart_button'); ?>
     79                    </form>
     80                    <?php
    8381                }
    8482            }
     
    8785
    8886    /**
     87     * Add multiple external buttons to loop in category
     88     * @since   1.1.0
     89     * @param $buttons
     90     * @param $product
     91     * @param $args
     92     * @return string
     93     */
     94    public function render_mepu_buttons_loop($buttons, $product, $args)
     95    {
     96        if (get_post_meta($product->get_id(), '_external_show_in_cat', true) && ('external' == $product->get_type())) {
     97            $mepu_data = get_post_meta($product->get_id(), '_multiple_external_');
     98            if (is_array($mepu_data[0])) {
     99                foreach ($mepu_data[0] as $mepu_item) {
     100                    $buttons .= sprintf('<a href="%s" data-quantity="%s" class="%s" %s>%s</a>',
     101                        esc_url($mepu_item[0]),
     102                        esc_attr(isset($args['quantity']) ? $args['quantity'] : 1),
     103                        esc_attr(isset($args['class']) ? $args['class'] : 'button'),
     104                        isset($args['attributes']) ? wc_implode_html_attributes($args['attributes']) : '',
     105                        esc_html($mepu_item[1]));
     106                }
     107            }
     108        }
     109
     110        return $buttons;
     111    }
     112
     113    /**
    89114     * Adjust cart form details
    90115     * @since   1.0.0
    91      * @param   int  $product_id ID of product
    92116     */
    93117    public function adjust_cart_form_details()
    94118    {
    95119        global $product;
    96         if($product) {
     120        if ($product) {
    97121            if ($product->get_type() == 'external') {
    98122                $mepu_data = get_post_meta($product->get_id(), '_external_target_blank', true);
     
    100124                    ?>
    101125                    <script>
    102                         if (jQuery('.cart')){
    103                             jQuery('.cart').attr('target','_blank');
     126                        if (jQuery('.cart')) {
     127                            jQuery('.cart').attr('target', '_blank');
    104128                        }
    105129                    </script>
     
    110134    }
    111135
     136    /**
     137     * Adjust external product buttons on category loop
     138     * @since   1.1.0
     139     * @param $args
     140     * @param $product
     141     * @return mixed
     142     */
     143    public function adjust_cart_form_details_loop($args, $product)
     144    {
     145        if (get_post_meta($product->get_id(), '_external_show_in_cat', true) && get_post_meta($product->get_id(), '_external_target_blank', true)) {
     146            $args['attributes']['target'] = '_blank';
     147        }
     148
     149        return $args;
     150    }
     151
    112152}
  • multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo.php

    r1933588 r2042986  
    179179        $this->loader->add_action('woocommerce_after_add_to_cart_form', $plugin, 'render_mepu_buttons');
    180180        $this->loader->add_action('woocommerce_after_add_to_cart_form', $plugin, 'adjust_cart_form_details');
     181
     182        $this->loader->add_filter('woocommerce_loop_add_to_cart_link', $plugin, 'render_mepu_buttons_loop', 10, 3);
     183        $this->loader->add_filter('woocommerce_loop_add_to_cart_args', $plugin, 'adjust_cart_form_details_loop', 10, 3);
    181184    }
    182185
  • multiple-external-product-urls-for-woocommerce/trunk/mepu-woo.php

    r1933588 r2042986  
    2828 * Rename this for your plugin and update it as you release new versions.
    2929 */
    30 define('MEPU_WOO_VERSION', '1.0.0');
     30define('MEPU_WOO_VERSION', '1.1.0');
    3131
    3232/**
Note: See TracChangeset for help on using the changeset viewer.