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