Created
September 21, 2017 08:28
-
-
Save masoninthesis/effdd7f418cfbbad9446c3efd60f6a86 to your computer and use it in GitHub Desktop.
/app/ drop in for WooCommerce Stores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_theme_support( 'woocommerce' ); | |
// Card block div for Product Loop | |
add_action( 'woocommerce_shop_loop_item_title', function () { | |
echo '<div class="card-block">'; | |
}, 1); | |
add_action( 'woocommerce_after_shop_loop_item', function () { | |
echo '</div>'; | |
}, 99); | |
// Shop Page | |
function remove_loop_button(){ | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); | |
} | |
add_action('init','remove_loop_button'); | |
add_action('woocommerce_after_shop_loop_item','replace_add_to_cart'); | |
function replace_add_to_cart() { | |
global $product; | |
$link = $product->get_permalink(); | |
echo do_shortcode('<a href="' . esc_attr($link) . '" class="btn btn-outline-primary read-more">Read more</a>'); | |
} | |
// Product Page | |
// Add Before Add to Cart on Product Page | |
// add_action( 'woocommerce_single_product_summary', 'return_policy', 20 ); | |
// | |
// function return_policy() { | |
// echo '<p class="small mute" id="rtrn"><em>We fulfill with Amazon for the fastest shipping possible – just 48 hours with Amazon Prime.</em></p>'; | |
// } | |
// Redirect to Cart on Add to Cart | |
function custom_add_to_cart_redirect() { | |
return '/cart/'; | |
} | |
add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' ); | |
// Mobile (xs-sm) Product Title | |
add_action( 'woocommerce_before_single_product_summary', 'product_title', 10 ); | |
function product_title() { | |
echo wp_kses_post( '<h1 class="text-center product_title_sm">' . get_the_title() . '</h1>'); | |
} | |
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 ); | |
function new_loop_shop_per_page( $cols ) { | |
// $cols contains the current number of products per page based on the value stored on Options -> Reading | |
// Return the number of products you wanna show per page. | |
$cols = 12; | |
return $cols; | |
} | |
// Hiding a Particular Category | |
// | |
// Category hiding | |
// | |
add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 ); | |
function get_subcategory_terms( $terms, $taxonomies, $args ) { | |
$new_terms = array(); | |
// if a product category and on the shop page | |
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) { | |
foreach ( $terms as $key => $term ) { | |
if ( ! in_array( $term->slug, array( 'adwords-listings', 'email-lander' ) ) ) { | |
$new_terms[] = $term; | |
} | |
} | |
$terms = $new_terms; | |
} | |
return $terms; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_theme_support( 'woocommerce' ); | |
// Card block div for Product Loop | |
add_action( 'woocommerce_shop_loop_item_title', function () { | |
echo '<div class="card-block">'; | |
}, 1); | |
add_action( 'woocommerce_after_shop_loop_item', function () { | |
echo '</div>'; | |
}, 99); | |
//////////// | |
// Shop Page | |
//////////// | |
function remove_loop_button(){ | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); | |
} | |
add_action('init','remove_loop_button'); | |
add_action('woocommerce_after_shop_loop_item','replace_add_to_cart'); | |
function replace_add_to_cart() { | |
global $product; | |
$link = $product->get_permalink(); | |
echo do_shortcode('<a href="' . esc_attr($link) . '" class="btn btn-outline-primary read-more">Read more</a>'); | |
} | |
/////////////// | |
// Product Page | |
/////////////// | |
// Add Before Add to Cart on Product Page | |
add_action( 'woocommerce_single_product_summary', 'return_policy', 100 ); | |
function return_policy() { | |
echo '<p class="small mute" id="rtrn"><em>Through our secure checkouts, you can enjoy within 48 hours.</em></p>'; | |
} | |
// Redirect to Cart on Add to Cart | |
function custom_add_to_cart_redirect() { | |
return '/bag/'; | |
} | |
add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' ); | |
// Mobile (xs-sm) Product Title | |
add_action( 'woocommerce_before_single_product_summary', 'product_title', 10 ); | |
function product_title() { | |
echo wp_kses_post( '<h1 class="text-center product_title_sm">' . get_the_title() . '</h1>'); | |
} | |
// Additional Add to Bag Button at End of Page | |
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_add_to_cart', 11 ); | |
add_action( 'woocommerce_after_single_product_summary', 'return_policy_2', 12 ); | |
function return_policy_2() { | |
echo '<p class="small mute mx-auto" id="rtrn"><em>Secure checkout. Free shipping, enjoy within 48 hours.</em></p>'; | |
} | |
// Changes Cart to Bag | |
function my_text_strings( $translated_text, $text, $domain ) { | |
switch ( $translated_text ) { | |
case 'View Cart' : | |
$translated_text = __( 'View bag', 'woocommerce' ); | |
break; | |
case 'Add to cart' : | |
$translated_text = __( 'Buy Now', 'woocommerce' ); | |
break; | |
case 'Update Cart' : | |
$translated_text = __( 'Update Bag', 'woocommerce' ); | |
break; | |
case 'Cart updated.' : | |
$translated_text = __( 'Bag updated.', 'woocommerce' ); | |
break; | |
case 'Cart Totals' : | |
$translated_text = __( 'Bag Totals', 'woocommerce' ); | |
break; | |
} | |
return $translated_text; | |
} | |
add_filter( 'gettext', 'my_text_strings', 20, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment