Skip to content

Instantly share code, notes, and snippets.

View 10horizons's full-sized avatar

10Horizons 10horizons

View GitHub Profile
@10horizons
10horizons / wprootdev-prevent-user-deletion.php
Last active October 29, 2022 05:23
How to prevent your account from being deleted by admins on WordPress.
<?php
function wproot_prevent_user_deletion( $deleting_userid ) {
$protected_userid = 1; //change 1 to the ID of the user you don't want to be deleted.
if ( $deleting_userid == $protected_userid ) {
$user_obj = get_user_by('id', $deleting_userid);
$name = $user_obj->user_login;
@10horizons
10horizons / thp_wc_change_download_expiry_based_on_quantity.php
Last active December 27, 2021 14:50
[Woocommerce] Change customer's download expiry date based on quantity purchased by customer, where quantity equals year. Fires after successful checkout but right before showing the thank you page.
<?php
function thp_wc_change_download_expiry_based_on_quantity( $order_id ) {
$order = wc_get_order( $order_id );
foreach ($order->get_items() as $item_id => $item ) {
$product = $item->get_product();
$product_id = $product->get_id();
@10horizons
10horizons / thp-remove-upsells.php
Created May 11, 2021 09:34
Prevent upsell products from being purchased without the main product
<?php
function thp_remove_upsells ($cart) {
$main_product_ID = 38; //CHANGE TO THE MAIN PRODUCT ID
$upsell_product_IDs = array( 39, 40 ); //CHANGE TO YOUR UPSELL PRODUCT ID's
$upsell_cart_keys = array();
$has_main_product = false;
$has_upsell = false;
@10horizons
10horizons / thp-wuppro-translation-gettext.php
Created May 5, 2021 18:52
Translate the "Added to cart" string on Woocommerce Upsell Popup PRO plugin using gettext hook.
<?php
function thp_wup_custom_change_strings( $translated_text, $text, $domain ) {
if ($domain == 'very-simple-woocommerce-upsell-popup') {
switch ($translated_text) {
case 'Added to Cart!' :
$translated_text = __( 'Tillagd i kundvagnen!', 'very-simple-woocommerce-upsell-popup' );
break;
}
@10horizons
10horizons / style.css
Created May 3, 2021 23:57
Woocommerce Upsell Popup PRO popup template known conflict with Flatsome theme (FIX)
.thp-popup-container .thp-flickity-container .thp-carousel .flickity-slider>div.thp-carousel-cell {
width: 24.5% !important;
}
.thp-popup-container .thp-flickity-container .thp-carousel button.flickity-prev-next-button {
opacity: 1 !important;
}
<?php
function thp_wup_custom_change_strings( $translated_text, $text, $domain ) {
if ($domain == 'very-simple-woocommerce-upsell-popup') {
switch ($translated_text) {
case 'The item has been added to cart. Thank you!' :
$translated_text = __( 'Der Artikel wurde in den Warenkorb gelegt. Vielen Dank!', 'very-simple-woocommerce-upsell-popup' );
break;
case 'Would you also be interested in this item?':
@10horizons
10horizons / thp_remove_upsell.php
Last active February 5, 2021 08:45
Prevent upsell product from being purchased on its own
<?php
function thp_remove_upsell ($cart) {
$main_product_ID = 38; //CHANGE TO THE MAIN PRODUCT ID
$upsell_product_ID = 39; //CHANGE TO YOUR UPSELL PRODUCT ID
$has_main_product = false;
$has_upsell = false;
foreach( $cart->get_cart() as $cart_item_key => $cart_item ) {
<?php
function my_custom_heading ($heading) {
return 'The novel has been made into a movie! ' . $heading;
}
add_filter( 'thp_mult_radio_template_heading', 'my_custom_heading' );
<?php
function my_custom_heading () {
return 'The novel has been made into a movie! Get the movie too?';
}
add_filter( 'thp_mult_radio_template_heading', 'my_custom_heading' );
<?php
function my_custom_subheading () {
echo '<p><span style="font-size: small; font-weight: bold; background: orange; color: #fff; text-align: center;">Stock is limited. Order now before they\'re all gone!</span></p>';
}
add_action( 'thp_mult_radio_template_before_radiobox', 'my_custom_subheading' );