This file contains hidden or 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
add_action( 'woocommerce_get_item_data', 'wc_ninja_add_custom_product_meta', 15, 2 ); | |
function wc_ninja_add_custom_product_meta( $other_data, $cart_item ) { | |
if ( ! empty( $cart_item['booking'] ) ) { | |
$item = $cart_item['booking']; | |
if ( 'night' === $item['_duration_unit'] ) { | |
$per_night = $item['_cost'] / $item['duration']; | |
$other_data[] = array( | |
'name' => 'Cost Per Night', |
This file contains hidden or 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
add_action( 'woocommerce_attribute_label', 'wc_ninja_change_attribute_label', 20, 3 ); | |
function wc_ninja_change_attribute_label( $label, $name, $product ) { | |
// Check if on single product page and if the attribute name is 'color' | |
if ( is_product() && 'color' === $name ) { | |
global $product; | |
// Change the label text based on the product ID | |
switch ( $product->id ) { | |
case '357': | |
$label = 'Custom Label One'; |
This file contains hidden or 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
add_action( 'woocommerce_after_shop_loop_item', 'wc_ninja_add_brands_to_archives', 6 ); | |
function wc_ninja_add_brands_to_archives() { | |
global $post; | |
$brand_count = sizeof( get_the_terms( $post->ID, 'product_brand' ) ); | |
$taxonomy = get_taxonomy( 'product_brand' ); | |
$labels = $taxonomy->labels; | |
echo get_brands( $post->ID, ', ', ' <div class="posted_in">' . sprintf( _n( '%1$s: ', '%2$s: ', $brand_count ), $labels->singular_name, $labels->name ), '</div>' ); | |
} |
This file contains hidden or 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
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wc_ninja_change_backorder_button', 10, 2 ); | |
function wc_ninja_change_backorder_button( $text, $product ){ | |
if ( $product->is_on_backorder( 1 ) ) { | |
$text = __( 'Pre-Order', 'woocommerce' ); | |
} | |
return $text; | |
} |
This file contains hidden or 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
function wc_ninja_add_to_billing_address( $formatted_billing_address, $type, $order ) { | |
if ( $order->billing_phone ) { | |
$formatted_billing_address .= "<br>" . $order->billing_phone; | |
} | |
if ( $order->billing_email ) { | |
$formatted_billing_address .= "<br>" . $order->billing_email; | |
} | |
return $formatted_billing_address; |
This file contains hidden or 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
add_action( 'woocommerce_after_add_to_cart_button', 'wc_ninja_add_extra_button', 20 ); | |
function wc_ninja_add_extra_button() { | |
echo "<a href='#' class='button'>Return to shop</a>"; | |
} |
This file contains hidden or 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
const watched = document.querySelectorAll( '.video.completed' ); | |
let totalSeconds = 0; | |
// Loop over each video watched. | |
watched.forEach( video => { | |
let videoTime = video.querySelector( 'span.duration' ).textContent.split( ':' ); | |
// Turn minutes:seconds into just seconds and append to totalSeconds. | |
videoTime.map( array => { | |
totalSeconds += ( parseInt( array[0] ) * 60 ) + parseInt( array[1] ); |
This file contains hidden or 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
// Rename the flat rate shipping label when the cost is $0 | |
function wc_ninja_change_flat_rate_label( $label, $method ) { | |
if ( 'flat_rate' == $method->method_id && $method->cost <= 0 ) { | |
$label = "Free Shipping"; | |
} | |
return $label; | |
} | |
add_filter( 'woocommerce_cart_shipping_method_full_label', 'wc_ninja_change_flat_rate_label', 10, 2 ); |
This file contains hidden or 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
add_action( 'woocommerce_after_cart_table', 'wc_ninja_remove_cart_addons', 10 ); | |
function wc_ninja_remove_cart_addons() { | |
global $sfn_cart_addons; | |
remove_action( 'woocommerce_after_cart_table', array( $sfn_cart_addons, 'cart_display_addons' ), 20 ); | |
} |
This file contains hidden or 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
add_action( 'woocommerce_get_price_html', 'wc_ninja_customize_price_html', 2, 10 ); | |
function wc_ninja_customize_price_html( $price, $product ) { | |
// Enter your product's ID here | |
$product_id = 87; | |
if ( $product_id == $product->id ) { | |
$price .= ' ($2.00 per piece)'; | |
} | |
return $price; |