add-to-cart
3 years ago
additional-information
3 years ago
advanced-search
3 years ago
archive-description
3 years ago
archive-products
3 years ago
archive-result-count
3 years ago
archive-title
3 years ago
archive-view-mode
3 years ago
breadcrumbs
4 years ago
cart-table
3 years ago
cart-totals
3 years ago
checkout-coupon-form
3 years ago
checkout-form-additional
3 years ago
checkout-form-billing
3 years ago
checkout-form-login
3 years ago
checkout-form-shipping
3 years ago
checkout-payment
3 years ago
checkout-review-order
3 years ago
checkout-shipping-methods
3 years ago
cross-sells
3 years ago
deal-products
3 years ago
empty-cart-message
4 years ago
filter-orderby
3 years ago
filter-products-per-page
4 years ago
filterable-product-list
3 years ago
init
3 years ago
notice
3 years ago
product-categories
3 years ago
product-category-lists
3 years ago
product-description
3 years ago
product-excerpt
3 years ago
product-image
3 years ago
product-list
3 years ago
product-meta
3 years ago
product-price
3 years ago
product-rating
3 years ago
product-review
3 years ago
product-share
3 years ago
product-sku
3 years ago
product-stock
3 years ago
product-tabs
3 years ago
product-tags
3 years ago
product-title
3 years ago
recently-viewed-products
3 years ago
related
3 years ago
return-to-shop
3 years ago
up-sells
3 years ago
view-single-product
3 years ago
lazy-cache.php
3 years ago
manifest.php
3 years ago
prod-short-code.php
3 years ago
products.php
3 years ago
shop.php
3 years ago
widget-helper.php
3 years ago
widget-helper.php
270 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Widgets; |
| 4 | |
| 5 | use ShopEngine\Traits\Singleton; |
| 6 | |
| 7 | class Widget_Helper { |
| 8 | |
| 9 | use Singleton; |
| 10 | |
| 11 | public function wc_template_filter_by_match($match, $replace_with) { |
| 12 | |
| 13 | add_filter( |
| 14 | 'wc_get_template', |
| 15 | function ( |
| 16 | $template, |
| 17 | $template_name = '', |
| 18 | $args = '', |
| 19 | $template_path = '', |
| 20 | $default_path = '' |
| 21 | ) use ($match, $replace_with) { |
| 22 | |
| 23 | if(strpos($template, $match) !== false) { |
| 24 | |
| 25 | $template = WC_ABSPATH . $replace_with; |
| 26 | |
| 27 | return $template; |
| 28 | } |
| 29 | |
| 30 | return $template; |
| 31 | } |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | public function wc_template_part_filter_by_match($match, $replace_with) { |
| 36 | |
| 37 | add_filter('wc_get_template_part', function ($template, $slug = '', $name = '') use ($match, $replace_with) { |
| 38 | |
| 39 | if(strpos($template, $match) !== false) { |
| 40 | |
| 41 | $template = WC_ABSPATH . $replace_with; |
| 42 | } |
| 43 | |
| 44 | return $template; |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | public function wc_template_part_filter() { |
| 49 | |
| 50 | add_filter('wc_get_template_part', function ($template, $slug = '', $name = '') { |
| 51 | |
| 52 | if(strpos($template, 'woocommerce/content-product.php') !== false) { |
| 53 | |
| 54 | $template = WC_ABSPATH . 'templates/content-product.php'; |
| 55 | |
| 56 | } elseif(strpos($template, 'woocommerce/content-product-base.php') !== false) { |
| 57 | |
| 58 | //$template = WC_ABSPATH . 'templates/content-product.php'; |
| 59 | |
| 60 | } |
| 61 | |
| 62 | return $template; |
| 63 | }, 999); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * replace single woocommerce template . |
| 68 | * alternative function for wc_template_part_filter_by_match, wc_template_filter_by_match |
| 69 | * |
| 70 | * @param $needle |
| 71 | * @param string $filter_tag |
| 72 | */ |
| 73 | public function wc_template_replace( $needle, $filter_tag = 'wc_get_template' ) { |
| 74 | add_filter( $filter_tag, function ( $template ) use ( $needle ) { |
| 75 | |
| 76 | if ( strpos( $template, 'woocommerce/' . $needle ) !== false ) { |
| 77 | $template = WC_ABSPATH . 'templates/' . $needle; |
| 78 | } |
| 79 | return $template; |
| 80 | }, 999 ); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * replace multiple woocommerce templates . |
| 85 | * alternative function for wc_template_part_filter_by_match, wc_template_filter_by_match, wc_template_part_filter,wc_template_filter |
| 86 | * |
| 87 | * @param $needles |
| 88 | * @param string $filter_tag |
| 89 | */ |
| 90 | public function wc_template_replace_multiple( $needles, $filter_tag = 'wc_get_template' ) { |
| 91 | add_filter($filter_tag, function ($template) use($needles){ |
| 92 | |
| 93 | foreach ($needles as $needle){ |
| 94 | if(strpos($template, 'woocommerce/'.$needle) !== false) { |
| 95 | $template = WC_ABSPATH . 'templates/'.$needle; |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | return $template; |
| 100 | }, 999); |
| 101 | } |
| 102 | |
| 103 | public function wc_template_filter() { |
| 104 | |
| 105 | add_filter('wc_get_template', function ($template, $template_name = '', $args = '', $template_path = '', $default_path = '') { |
| 106 | |
| 107 | if(strpos($template, 'woocommerce/global/breadcrumb.php') !== false) { |
| 108 | |
| 109 | $template = WC_ABSPATH . 'templates/global/breadcrumb.php'; |
| 110 | |
| 111 | } elseif(strpos($template, 'single-product/up-sells.php') !== false) { |
| 112 | |
| 113 | $template = WC_ABSPATH . 'templates/single-product/up-sells.php'; |
| 114 | |
| 115 | } elseif(strpos($template, 'woocommerce/loop/loop-start.php') !== false) { |
| 116 | |
| 117 | $template = WC_ABSPATH . 'templates/loop/loop-start.php'; |
| 118 | |
| 119 | } elseif(strpos($template, 'woocommerce/loop/loop-end.php') !== false) { |
| 120 | |
| 121 | $template = WC_ABSPATH . 'templates/loop/loop-end.php'; |
| 122 | |
| 123 | } elseif(strpos($template, 'woocommerce/global/wrapper-end.php') !== false) { |
| 124 | |
| 125 | $template = WC_ABSPATH . 'templates/global/wrapper-end.php'; |
| 126 | |
| 127 | } elseif(strpos($template, 'woocommerce/global/wrapper-start.php') !== false) { |
| 128 | |
| 129 | $template = WC_ABSPATH . 'templates/global/wrapper-start.php'; |
| 130 | |
| 131 | } elseif(strpos($template, 'woocommerce/loop/sale-flash.php') !== false) { |
| 132 | |
| 133 | $template = WC_ABSPATH . 'templates/loop/sale-flash.php'; |
| 134 | |
| 135 | } elseif(strpos($template, 'woocommerce/single-product/product-image.php') !== false) { |
| 136 | |
| 137 | $template = WC_ABSPATH . 'templates/single-product/product-image.php'; |
| 138 | |
| 139 | } elseif(strpos($template, 'woocommerce/single-product/product-thumbnails.php') !== false) { |
| 140 | |
| 141 | $template = WC_ABSPATH . 'templates/single-product/product-thumbnails.php'; |
| 142 | |
| 143 | } elseif(strpos($template, 'woocommerce/global/wrapper-end.php') !== false) { |
| 144 | |
| 145 | $template = WC_ABSPATH . 'templates/global/wrapper-end.php'; |
| 146 | |
| 147 | } elseif(strpos($template, 'woocommerce/global/wrapper-start.php') !== false) { |
| 148 | |
| 149 | $template = WC_ABSPATH . 'templates/global/wrapper-start.php'; |
| 150 | |
| 151 | } elseif(strpos($template, 'woocommerce/loop/result-count.php') !== false) { |
| 152 | |
| 153 | $template = WC_ABSPATH . 'templates/loop/result-count.php'; |
| 154 | |
| 155 | } elseif(strpos($template, 'woocommerce/loop/rating.php') !== false) { |
| 156 | |
| 157 | $template = WC_ABSPATH . 'templates/loop/rating.php'; |
| 158 | |
| 159 | } elseif(strpos($template, 'woocommerce/loop/add-to-cart.php') !== false) { |
| 160 | |
| 161 | $template = WC_ABSPATH . 'templates/loop/add-to-cart.php'; |
| 162 | |
| 163 | } elseif(strpos($template, 'woocommerce/single-product/product-thumbnails.php') !== false) { |
| 164 | |
| 165 | $template = WC_ABSPATH . 'templates/single-product/product-thumbnails.php'; |
| 166 | |
| 167 | } elseif(strpos($template, 'woocommerce/single-product/product-image.php') !== false) { |
| 168 | |
| 169 | $template = WC_ABSPATH . 'templates/single-product/product-image.php'; |
| 170 | |
| 171 | } elseif(strpos($template, 'woocommerce/single-product/related.php') !== false) { |
| 172 | |
| 173 | $template = WC_ABSPATH . 'templates/single-product/related.php'; |
| 174 | |
| 175 | } elseif(strpos($template, 'woocommerce/single-product/up-sells.php') !== false) { |
| 176 | |
| 177 | $template = WC_ABSPATH . 'templates/single-product/up-sells.php'; |
| 178 | |
| 179 | } elseif(strpos($template, 'woocommerce/cart/cross-sells.php') !== false) { |
| 180 | |
| 181 | $template = WC_ABSPATH . 'templates/cart/cross-sells.php'; |
| 182 | |
| 183 | } elseif(strpos($template, 'woocommerce/cart/cart-shipping.php') !== false) { |
| 184 | |
| 185 | $template = WC_ABSPATH . 'templates/cart/cart-shipping.php'; |
| 186 | |
| 187 | } elseif(strpos($template, 'woocommerce/myaccount/my-address.php') !== false) { |
| 188 | |
| 189 | $template = WC_ABSPATH.'templates/myaccount/my-address.php'; |
| 190 | |
| 191 | } elseif(strpos($template, 'woocommerce/myaccount/dashboard.php') !== false) { |
| 192 | |
| 193 | $template = WC_ABSPATH.'templates/myaccount/dashboard.php'; |
| 194 | |
| 195 | } elseif(strpos($template, 'woocommerce/order/order-details.php') !== false) { |
| 196 | |
| 197 | $template = WC_ABSPATH.'templates/order/order-details.php'; |
| 198 | |
| 199 | } elseif(strpos($template, 'woocommerce/order/order-downloads.php') !== false) { |
| 200 | |
| 201 | $template = WC_ABSPATH.'templates/order/order-downloads.php'; |
| 202 | |
| 203 | } elseif(strpos($template, 'woocommerce/content-product.php') !== false) { |
| 204 | |
| 205 | $template = WC_ABSPATH . 'templates/content-product.php'; |
| 206 | |
| 207 | } elseif(strpos($template, 'woocommerce/order/order-details-customer.php') !== false) { |
| 208 | |
| 209 | $template = WC_ABSPATH.'templates/order/order-details-customer.php'; |
| 210 | |
| 211 | } elseif(strpos($template, 'woocommerce/loop/pagination.php') !== false) { |
| 212 | |
| 213 | $template = WC_ABSPATH.'templates/loop/pagination.php'; |
| 214 | |
| 215 | } elseif(strpos($template, 'woocommerce/myaccount/orders.php') !== false) { |
| 216 | |
| 217 | $template = WC_ABSPATH.'templates/myaccount/orders.php'; |
| 218 | |
| 219 | } elseif(strpos($template, 'woocommerce/myaccount/downloads.php') !== false) { |
| 220 | |
| 221 | $template = WC_ABSPATH.'templates/myaccount/downloads.php'; |
| 222 | |
| 223 | } elseif(strpos($template, 'woocommerce/checkout/terms.php') !== false) { |
| 224 | |
| 225 | $template = WC_ABSPATH.'templates/checkout/terms.php'; |
| 226 | |
| 227 | } |
| 228 | return $template; |
| 229 | }, 999); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | public function wc_breadcrumb_default_filter($iconClass) { |
| 234 | |
| 235 | add_filter('woocommerce_breadcrumb_defaults', function ($param) use ($iconClass) { |
| 236 | |
| 237 | $param['delimiter'] = '<i class="' . $iconClass . '" aria-hidden="true"></i>'; |
| 238 | $param['wrap_before'] = '<nav class="woocommerce-breadcrumb">'; |
| 239 | $param['wrap_after'] = '</nav>'; |
| 240 | |
| 241 | return $param; |
| 242 | }, 999); |
| 243 | } |
| 244 | |
| 245 | public function comment_template_filter_checker() { |
| 246 | |
| 247 | add_filter('comments_template', function ($template) { |
| 248 | |
| 249 | if(strpos($template, '/single-product-advanced-reviews.php') !== false) { |
| 250 | |
| 251 | /** |
| 252 | * Fix for electro theme................. |
| 253 | */ |
| 254 | |
| 255 | $template = WC_ABSPATH . 'templates/single-product-reviews.php'; |
| 256 | |
| 257 | } elseif(strpos($template, '/woocommerce/single-product-reviews.php') !== false) { |
| 258 | |
| 259 | /** |
| 260 | * Fix for all other theme................. |
| 261 | */ |
| 262 | |
| 263 | $template = WC_ABSPATH . 'templates/single-product-reviews.php'; |
| 264 | } |
| 265 | |
| 266 | return $template; |
| 267 | }, 999); |
| 268 | } |
| 269 | } |
| 270 |