Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
webtoffee-git / functions.php
Created November 5, 2024 09:20
To add the site title as a link in the footer - by WebToffee ( Decorator- WooCommerce Email Customiser )
<?php // Do not copy this line of code
add_filter('woocommerce_email_footer_text', function($footer_text){
$site_url = site_url();
$site_name = get_bloginfo('name','display');
$footer_text = str_replace(
'{site_title}',
'<a href="' . esc_url($site_url) . '" target="_blank" >' . esc_html($site_name) . '</a>',
$footer_text
);
return $footer_text;
@webtoffee-git
webtoffee-git / functions.php
Last active October 24, 2024 07:21
Code snippet for Colissimo plugin compatibility with the WebToffee PayPal plugin to include pickup details in the shipping address of order - By WebToffee (Paypal Payment Gateway plugin - Basic)
<?php // Do not copy this line of code
add_action("wt_woocommerce_checkout_order_created", "wt_woocommerce_checkout_order_creat", 10, 2);
function wt_woocommerce_checkout_order_creat($order, $checkout_post){
$obj = new LpcPickupSelection();
if (!$order->has_shipping_method('lpc_relay')) {
return;
}
$shipping = array();
$pickupData = $obj->getCurrentPickUpLocationInfo();
if(isset($pickupData['adresse1']) && !empty($pickupData['adresse1'])){
@webtoffee-git
webtoffee-git / functions.php
Last active December 2, 2024 12:07
Code to fetch older object using order number - By WebToffee( Sequential Order Number for WooCommerce )
<?php //Do not copy this line of code
$ordernid = '12345'; //order number
// Check if HPOS is enabled
if (get_option('woocommerce_custom_orders_table_enabled') === 'yes') {
global $wpdb;
$order_id = $wpdb->get_var(
$wpdb->prepare(
"SELECT order_id FROM {$wpdb->prefix}wc_orders_meta
WHERE meta_key = %s AND meta_value = %s LIMIT 1",
'_order_number',
@webtoffee-git
webtoffee-git / functions.php
Last active October 17, 2024 09:37
Code to force disconnect the Stripe app - By WebToffee (Stripe Payment Gateway for WooCommerce)
<?php //Do not copy this line of code
add_action("admin_init", "wt_disconnect_app");
function wt_disconnect_app(){
if(isset($_REQUEST['page']) && "wt_stripe_menu" === sanitize_text_field($_REQUEST['page']) && isset($_REQUEST['action']) && "delete_app" === sanitize_text_field($_REQUEST['action'])){
delete_transient("wtst_refresh_token_calling");
//Sandobx tokens
delete_option("wt_stripe_account_id_test");
delete_option("wt_stripe_access_token_test");
delete_option("wt_stripe_refresh_token_test");
@webtoffee-git
webtoffee-git / functions.php
Last active October 18, 2024 07:15
Stripe card icon customisation - By WebToffee
<?php //Do not copy this line of code
add_action("wp_footer", "wt_customize_stripe_icons");
function wt_customize_stripe_icons(){
?><style type="text/css">
#payment .payment_methods li img {
float: right;
}
@media only screen and (max-width: 480px) {
@webtoffee-git
webtoffee-git / functions.php
Created October 14, 2024 13:10
To prevent old order numbers getting updated while changing order status - By WebToffee (Sequential Order Number for WooCommerce Free)
<?php //Do not copy this line of code
add_action('init', 'remove_order_status_changed_order_number', 15);
function remove_order_status_changed_order_number() {
if (class_exists('Wt_Advanced_Order_Number')) {
foreach ($GLOBALS['wp_filter']['woocommerce_order_status_changed']->callbacks as $priority => $hooks) {
foreach ($hooks as $hook_id => $hook) {
if (is_array($hook['function']) && is_object($hook['function'][0])) {
$object = $hook['function'][0];
@webtoffee-git
webtoffee-git / functions.php
Last active October 11, 2024 06:35
Code to set the default order status for card payments to 'On Hold' - By WebToffee ( Stripe Payment Gateway)
<?php //Do not copy this line of code
add_action('woocommerce_thankyou', 'set_order_status_on_hold', 10, 1);
function set_order_status_on_hold($order_id) {
// Get the order object
$order = wc_get_order($order_id);
// Check if the order exists and if the payment method is your custom one
if ($order && $order->get_payment_method() === 'eh_stripe_pay') {
// Set the order status to 'on-hold'
$order->update_status('on-hold', __('Order status set to on hold by custom payment method.', 'payment_gateway_stripe_and_woocommerce_integration'));
@webtoffee-git
webtoffee-git / functions.php
Last active October 12, 2024 04:02
Fix compatibility issue with Curcy Multi Currency plugin on the Gift Card product page - By WebToffee (WebToffee Gift Cards plugin)
<?php //Do no copy this line of code
//Currency converter function
if(! function_exists('convert_curcy_price')){
function convert_curcy_price( $price, $selected_currency, $previous_currency='') {
if(class_exists('WOOMULTI_CURRENCY_F') && method_exists('WOOMULTI_CURRENCY_F_Data','get_ins')){
$curcy_currency_settings = WOOMULTI_CURRENCY_F_Data::get_ins();
$currency_list = $curcy_currency_settings->get_list_currencies();
$force_convert = false;
if( ''!== $previous_currency && $previous_currency !== $selected_currency ){
@webtoffee-git
webtoffee-git / functions.php
Last active September 16, 2024 12:44
Compatibility with WOOCS currency switcher with invoice basic plugin - By WebToffee
<?php //Do not copy this line of code
add_filter('wt_pklist_alter_currency_symbol', 'wt_pklist_alter_currency_symbol_fun', 9999, 5);
function wt_pklist_alter_currency_symbol_fun($wc_currency_symbol, $symbols, $user_currency, $order, $price) {
if ( $order instanceof WC_Order ) {
$currency = $order->get_currency();
$symbols = get_woocommerce_currency_symbols();
return $symbols[$currency] ?? $wc_currency_symbol;
}
@webtoffee-git
webtoffee-git / functions.php
Created September 11, 2024 09:33
Code snippet to remove address fields from "Form address" in the Shipping label document - By WebToffee(WooCommerce PDF Invoice, Packing Slips, Delivery Notes and Shipping labels)
<?php //Do not copy this line of code
add_filter('wf_pklist_alter_shipping_from_address', 'wt_pklist_alter_from_addr', 10, 3);
function wt_pklist_alter_from_addr($fromaddress, $template_type, $order) {
if ( 'shippinglabel' === $template_type ) {
// Define address fields to remove from the "From" address
$address_fields = [
'address_line1',
'address_line2',
'city',