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
// Add custom HTML to the WooCommerce thank you page | |
add_action('woocommerce_thankyou', 'custom_html_confirmation_page_1001'); | |
function custom_html_confirmation_page_1001($order_id) { | |
$order = wc_get_order($order_id); | |
echo '<div class="custom-confirmation-message">'; | |
echo '<h2>Thank you for your purchase!</h2>'; | |
echo '<p>Your order number is: ' . $order->get_order_number() . '</p>'; | |
echo '<p>We appreciate your business and will send you a confirmation email shortly.</p>'; | |
echo '</div>'; | |
} |
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
// Version 1.0 | |
function add_tiktok_pixel() { | |
?> | |
<!-- TikTok Pixel Code --> | |
<script> | |
!function (w, d, t) { | |
w.TiktokAnalyticsObject = t; | |
var ttq = w[t] = w[t] || []; | |
ttq.methods = ["page", "track", "identify", "instances", "debug", "on", "off", "once", "ready", "alias", "group", "enableCookie", "disableCookie"]; | |
ttq.setAndDefer = function (t, e) { |
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
add_filter('woocommerce_package_rates', 'wpsites_remove_flat_rate_methods_over_150', 10, 2); | |
function wpsites_remove_flat_rate_methods_over_150($rates, $package) { | |
$cart_total = WC()->cart->get_cart_contents_total(); | |
$threshold = 150; | |
// Define the shipping method IDs to remove if cart total exceeds $150 | |
$methods_to_remove = array( | |
'flat_rate:12', |
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
add_filter('woocommerce_package_rates', 'switch_flat_rate_based_on_total_v3', 10, 2); | |
function switch_flat_rate_based_on_total_v3($rates, $package) { | |
$cart_total = WC()->cart->get_cart_contents_total(); | |
$flat_rate_5 = 'flat_rate:5'; // ID for flat rate 5 | |
$flat_rate_7 = 'flat_rate:7'; // ID for flat rate 7 | |
if ($cart_total > 150) { | |
if (isset($rates[$flat_rate_5])) { | |
unset($rates[$flat_rate_5]); |
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
add_filter( 'single_template', 'wpsites_single_post_type_template' ); | |
function wpsites_single_post_type_template($single_template) { | |
global $post; | |
if ($post->post_type == 'post' ) { | |
$single_template = dirname( __FILE__ ) . '/single.php'; | |
} | |
return $single_template; | |
} |
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
add_action('woocommerce_product_options_general_product_data', 'add_custom_fields'); | |
function add_custom_fields() { | |
woocommerce_wp_text_input( array( | |
'id' => '_shipping_detail', | |
'label' => 'Shipping Detail', | |
'desc_tip' => 'true', | |
'description' => 'Enter the shipping details.', | |
)); | |
woocommerce_wp_text_input( array( |
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
add_action( 'woocommerce_before_add_to_cart_button', 'custom_product_addons', 10 ); | |
function custom_product_addons() { | |
global $product; | |
$product_price = $product->get_price(); // Base price of the product. | |
?> | |
<div id="product-warranty-addons"> | |
<p>Select Additional Warranty:</p> | |
<button type="button" class="warranty-addon" data-addon="15" data-price="<?php echo esc_attr( $product_price ); ?>"> | |
Additional 4-Month Warranty (+15%) | |
</button> |
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
add_action('woocommerce_order_status_completed', 'track_completed_orders_101', 10, 1); | |
function track_completed_orders_101($order_id) { | |
$order = wc_get_order($order_id); | |
$user_id = $order->get_user_id(); | |
if ($user_id) { | |
$completed_orders = get_user_meta($user_id, '_completed_orders_count', true); | |
$completed_orders = $completed_orders ? $completed_orders + 1 : 1; | |
update_user_meta($user_id, '_completed_orders_count', $completed_orders); | |
} |
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
add_action( 'woocommerce_after_single_product', 'wpsitesdotnet_custom_wc_wp_query' ); | |
function wpsitesdotnet_custom_wc_wp_query() { | |
echo '<ul class="products">'; | |
$args = array( | |
'post_type' => 'product', | |
'posts_per_page' => 3 | |
); |
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
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40); | |
add_action('woocommerce_single_product_summary', 'custom_display_limited_product_categories', 40); | |
function custom_display_limited_product_categories() { | |
global $product; | |
$categories = wp_get_post_terms( $product->get_id(), 'product_cat', array('orderby' => 'name', 'order' => 'ASC', 'number' => 1)); // Limit to 3 categories | |
if ( $categories && !is_wp_error( $categories ) ) { | |
NewerOlder