Changeset 2042986
- Timestamp:
- 03/02/2019 11:06:09 PM (6 years ago)
- 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 4 4 Tags: woocommerce, external product, woo, external, product, product url 5 5 Requires at least: 3.0.1 6 Tested up to: 4.9.87 Stable tag: 1. 0.06 Tested up to: 5.1 7 Stable tag: 1.1.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 35 35 == Changelog == 36 36 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 37 43 = 1.0.0 = 38 44 * Initial release -
multiple-external-product-urls-for-woocommerce/tags/1.1.0/admin/class-mepu-woo-additional-fields.php
r1933588 r2042986 78 78 $multiple_external_fields = array(); 79 79 } 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'>"; 81 81 82 82 ?> … … 89 89 'label' => __( 'Open in new tab', 'mepu-woo' ), 90 90 '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') 91 99 ) 92 100 ); … … 129 137 $fine_array = array(); 130 138 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' ) ) ) { 132 141 return false; 133 142 } … … 153 162 ); 154 163 164 update_post_meta( 165 $post_id, 166 '_external_show_in_cat', 167 esc_attr($_POST['_external_show_in_cat']) 168 ); 169 155 170 } 156 171 -
multiple-external-product-urls-for-woocommerce/tags/1.1.0/frontend/class-mepu-woo-frontend.php
r1933588 r2042986 59 59 * Render all buttons to external shops on product page 60 60 * @since 1.0.0 61 * @param int $product_id ID of product62 61 */ 63 62 public function render_mepu_buttons() 64 63 { 65 64 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'); ?> 74 72 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> 76 75 77 <?php wc_query_string_form_fields( $mepu_item[0]); ?>76 <?php wc_query_string_form_fields($mepu_item[0]); ?> 78 77 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 83 81 } 84 82 } … … 87 85 88 86 /** 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 /** 89 114 * Adjust cart form details 90 115 * @since 1.0.0 91 * @param int $product_id ID of product92 116 */ 93 117 public function adjust_cart_form_details() 94 118 { 95 119 global $product; 96 if ($product) {120 if ($product) { 97 121 if ($product->get_type() == 'external') { 98 122 $mepu_data = get_post_meta($product->get_id(), '_external_target_blank', true); … … 100 124 ?> 101 125 <script> 102 if (jQuery('.cart')) {103 jQuery('.cart').attr('target', '_blank');126 if (jQuery('.cart')) { 127 jQuery('.cart').attr('target', '_blank'); 104 128 } 105 129 </script> … … 110 134 } 111 135 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 112 152 } -
multiple-external-product-urls-for-woocommerce/tags/1.1.0/includes/class-mepu-woo.php
r1933588 r2042986 179 179 $this->loader->add_action('woocommerce_after_add_to_cart_form', $plugin, 'render_mepu_buttons'); 180 180 $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); 181 184 } 182 185 -
multiple-external-product-urls-for-woocommerce/tags/1.1.0/mepu-woo.php
r1933588 r2042986 28 28 * Rename this for your plugin and update it as you release new versions. 29 29 */ 30 define('MEPU_WOO_VERSION', '1. 0.0');30 define('MEPU_WOO_VERSION', '1.1.0'); 31 31 32 32 /** -
multiple-external-product-urls-for-woocommerce/trunk/README.txt
r1933588 r2042986 4 4 Tags: woocommerce, external product, woo, external, product, product url 5 5 Requires at least: 3.0.1 6 Tested up to: 4.9.87 Stable tag: 1. 0.06 Tested up to: 5.1 7 Stable tag: 1.1.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 35 35 == Changelog == 36 36 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 37 43 = 1.0.0 = 38 44 * Initial release -
multiple-external-product-urls-for-woocommerce/trunk/admin/class-mepu-woo-additional-fields.php
r1933588 r2042986 78 78 $multiple_external_fields = array(); 79 79 } 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'>"; 81 81 82 82 ?> … … 89 89 'label' => __( 'Open in new tab', 'mepu-woo' ), 90 90 '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') 91 99 ) 92 100 ); … … 129 137 $fine_array = array(); 130 138 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' ) ) ) { 132 141 return false; 133 142 } … … 153 162 ); 154 163 164 update_post_meta( 165 $post_id, 166 '_external_show_in_cat', 167 esc_attr($_POST['_external_show_in_cat']) 168 ); 169 155 170 } 156 171 -
multiple-external-product-urls-for-woocommerce/trunk/frontend/class-mepu-woo-frontend.php
r1933588 r2042986 59 59 * Render all buttons to external shops on product page 60 60 * @since 1.0.0 61 * @param int $product_id ID of product62 61 */ 63 62 public function render_mepu_buttons() 64 63 { 65 64 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'); ?> 74 72 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> 76 75 77 <?php wc_query_string_form_fields( $mepu_item[0]); ?>76 <?php wc_query_string_form_fields($mepu_item[0]); ?> 78 77 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 83 81 } 84 82 } … … 87 85 88 86 /** 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 /** 89 114 * Adjust cart form details 90 115 * @since 1.0.0 91 * @param int $product_id ID of product92 116 */ 93 117 public function adjust_cart_form_details() 94 118 { 95 119 global $product; 96 if ($product) {120 if ($product) { 97 121 if ($product->get_type() == 'external') { 98 122 $mepu_data = get_post_meta($product->get_id(), '_external_target_blank', true); … … 100 124 ?> 101 125 <script> 102 if (jQuery('.cart')) {103 jQuery('.cart').attr('target', '_blank');126 if (jQuery('.cart')) { 127 jQuery('.cart').attr('target', '_blank'); 104 128 } 105 129 </script> … … 110 134 } 111 135 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 112 152 } -
multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo.php
r1933588 r2042986 179 179 $this->loader->add_action('woocommerce_after_add_to_cart_form', $plugin, 'render_mepu_buttons'); 180 180 $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); 181 184 } 182 185 -
multiple-external-product-urls-for-woocommerce/trunk/mepu-woo.php
r1933588 r2042986 28 28 * Rename this for your plugin and update it as you release new versions. 29 29 */ 30 define('MEPU_WOO_VERSION', '1. 0.0');30 define('MEPU_WOO_VERSION', '1.1.0'); 31 31 32 32 /**
Note: See TracChangeset
for help on using the changeset viewer.