Snippets

Barn2 Plugins Replace Up-Sells with WooCommerce Product Table

Updated by Paul Houser

File snippet.txt Deleted

  • Ignore whitespace
  • Hide word diff
-<?php
-/**
- * Single Product Up-Sells
- *
- * This template can be overridden by copying it to yourtheme/woocommerce/single-product/up-sells.php.
- *
- * HOWEVER, on occasion WooCommerce will need to update template files and you
- * (the theme developer) will need to copy the new files to your theme to
- * maintain compatibility. We try to do this as little as possible, but it does
- * happen. When this occurs the version of the template file will be bumped and
- * the readme will list any important changes.
- *
- * @see         https://docs.woocommerce.com/document/template-structure/
- * @package     WooCommerce\Templates
- * @version     3.0.0
- */
-
-if ( ! defined( 'ABSPATH' ) ) {
-	exit;
-}
-if ( ! $upsells ) {
-    return;
-} 
-
-$ids = [];
-foreach ( $upsells as $upsell ) {
-    $ids[] = $upsell->get_id();
-}
-
-// You can customize the shortcode according your site's needs. Replace
-// everything between the quote marks with your product_table shortcode of
-// choice. Just make sure to leave the `include="%s"` part in tact.
-$shortcode = '[product_table include="%s"]';
-
-?>
-
-<section class="up-sells upsells products">
-	<?php
-	$heading = apply_filters( 'woocommerce_product_upsells_products_heading', __( 'You may also like&hellip;', 'woocommerce' ) );
-
-	if ( $heading ) :
-		?>
-		<h2><?php echo esc_html( $heading ); ?></h2>
-	<?php endif; ?>
-
-	<?php echo do_shortcode( sprintf( $shortcode, implode( ',', $ids ) ) ); ?>
-
-</section>

File up-sells.php Added

  • Ignore whitespace
  • Hide word diff
+<?php
+/**
+ * Single Product Up-Sells
+ *
+ * This template can be overridden by copying it to yourtheme/woocommerce/single-product/up-sells.php.
+ *
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
+ * (the theme developer) will need to copy the new files to your theme to
+ * maintain compatibility. We try to do this as little as possible, but it does
+ * happen. When this occurs the version of the template file will be bumped and
+ * the readme will list any important changes.
+ *
+ * @see         https://docs.woocommerce.com/document/template-structure/
+ * @package     WooCommerce\Templates
+ * @version     3.0.0
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+	exit;
+}
+if ( ! $upsells ) {
+    return;
+} 
+
+$ids = [];
+foreach ( $upsells as $upsell ) {
+    $ids[] = $upsell->get_id();
+}
+
+// You can customize the shortcode according your site's needs. Replace
+// everything between the quote marks with your product_table shortcode of
+// choice. Just make sure to leave the `include="%s"` part in tact.
+$shortcode = '[product_table include="%s"]';
+
+?>
+
+<section class="up-sells upsells products">
+	<?php
+	$heading = apply_filters( 'woocommerce_product_upsells_products_heading', __( 'You may also like&hellip;', 'woocommerce' ) );
+
+	if ( $heading ) :
+		?>
+		<h2><?php echo esc_html( $heading ); ?></h2>
+	<?php endif; ?>
+
+	<?php echo do_shortcode( sprintf( $shortcode, implode( ',', $ids ) ) ); ?>
+
+</section>
Created by Paul Houser

File snippet.txt Added

  • Ignore whitespace
  • Hide word diff
+<?php
+/**
+ * Single Product Up-Sells
+ *
+ * This template can be overridden by copying it to yourtheme/woocommerce/single-product/up-sells.php.
+ *
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
+ * (the theme developer) will need to copy the new files to your theme to
+ * maintain compatibility. We try to do this as little as possible, but it does
+ * happen. When this occurs the version of the template file will be bumped and
+ * the readme will list any important changes.
+ *
+ * @see         https://docs.woocommerce.com/document/template-structure/
+ * @package     WooCommerce\Templates
+ * @version     3.0.0
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+	exit;
+}
+if ( ! $upsells ) {
+    return;
+} 
+
+$ids = [];
+foreach ( $upsells as $upsell ) {
+    $ids[] = $upsell->get_id();
+}
+
+// You can customize the shortcode according your site's needs. Replace
+// everything between the quote marks with your product_table shortcode of
+// choice. Just make sure to leave the `include="%s"` part in tact.
+$shortcode = '[product_table include="%s"]';
+
+?>
+
+<section class="up-sells upsells products">
+	<?php
+	$heading = apply_filters( 'woocommerce_product_upsells_products_heading', __( 'You may also like&hellip;', 'woocommerce' ) );
+
+	if ( $heading ) :
+		?>
+		<h2><?php echo esc_html( $heading ); ?></h2>
+	<?php endif; ?>
+
+	<?php echo do_shortcode( sprintf( $shortcode, implode( ',', $ids ) ) ); ?>
+
+</section>
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.