Skip to content

Instantly share code, notes, and snippets.

<?php
add_action('woocommerce_cart_calculate_fees', 'ts_add_custom_discount', 10, 1 );
function ts_add_custom_discount( $wc_cart ){
$discount = 0;
$product_ids = array();
$in_cart = false;
foreach ( $wc_cart->get_cart() as $cart_item_key => $cart_item ) {
$cart_product = $cart_item['data'];
if ( has_term( 'get2', 'product_cat', $cart_product->get_id() ) ) {
$in_cart = true;
<?php
add_action('woocommerce_cart_calculate_fees', 'ts_add_custom_discount', 10, 1 );
function ts_add_custom_discount( $wc_cart ){
$discount = 0;
$product_ids = array();
$in_cart = false;
foreach ( $wc_cart->get_cart() as $cart_item_key => $cart_item ) {
$cart_product = $cart_item['data'];
if ( has_term( 'get2', 'product_cat', $cart_product->get_id() ) ) {
$in_cart = true;
<?php
add_action('woocommerce_cart_calculate_fees', 'ts_add_custom_discount', 10, 1 );
function ts_add_custom_discount( $wc_cart ){
$discount = 0;
$product_ids = array();
$in_cart = false;
foreach ( $wc_cart->get_cart() as $cart_item_key => $cart_item ) {
$cart_product = $cart_item['data'];
<?php
add_filter('woocommerce_add_cart_item', 'ts_add_cart_item', 10, 1 );
function ts_add_cart_item( $cart_item ) {
$product_id = $cart_item[ 'data' ]->get_id();
$product = wc_get_product( $product_id );
if( false == $cart_item[ 'offer' ] ) {
$cart_item[ 'offer' ] = 0;
}
<?php
add_filter('woocommerce_add_cart_item_data', 'add_to_cart', 10, 2 );
function add_to_cart( $cart_item_meta, $product_id ) {
//var_dump( $cart_item_key );
$product = wc_get_product( $product_id );
$in_cart = false;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
# code...
$cart_product = $cart_item['data'];
<?php
add_action('woocommerce_before_shop_loop_item', 'ts_before_shop_loop_item' ) ;
function ts_before_shop_loop_item() {
$product_id = get_the_ID();
$current_date = date( current_time( 'timestamp' ) );
$product_date = get_the_date();
$date_diff = strtotime( $current_date) - strtotime( $product_date );
$number_of_days = $date_diff/ (60*60*24);
<?php
add_action('woocommerce_before_shop_loop_item', 'ts_before_shop_loop_item' ) ;
function ts_before_shop_loop_item() {
echo "Hello World";
}
<?php
add_action( 'woocommerce_after_main_content', 'after_main_content', 1 );
function after_main_content() {
echo "<div class='best-seller'>
<h3>If you need help or have a question for Customer Service, please visit the <a href='#'>Help Section.</a></h3>
</div";
}
<?php
add_action( 'woocommerce_after_shop_loop', 'after_shop_loop', 1 );
function after_shop_loop() {
$id = 57;
$product = wc_get_product( $id );
$url = get_permalink($id);
echo "<a href='".$url."'>
<?php
add_action( 'woocommerce_after_shop_loop_item', 'after_shop_loop_item', 1 );
function after_shop_loop_item() {
global $post;
if( $post->ID == 57 || $post->ID == 59 ) {
echo "<div class='best-seller'>
<h3>Recommended</h3>
</div>";