Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
webtoffee-git / functions.php
Created November 11, 2024 06:15
Code snippet to alter product image URL in documents - by WebToffee ( WooCommerce PDF Invoice, Packing Slips, Delivery Notes and Shipping labels (free)
<?php //Do not copy this line of code
add_filter('wt_pklist_alter_product_image_url', 'wt_pklist_alter_product_image_url_fn', 10, 4);
/**
* Filter to customize the product image URL in packing lists.
*
* This function allows you to set a custom image URL for a product.
* If a custom image URL is available, update the `$img_url` variable to use that URL.
* @return string The updated image URL to be used in the packing list.
*/
function wt_pklist_alter_product_image_url_fn($img_url, $product_id, $variation_id, $parent_id) {
@webtoffee-git
webtoffee-git / functions.php
Created November 5, 2024 11:24
Code snippet to modify the order date format in documents - By WebToffee( WooCommerce PDF Invoice, Packing Slips, Delivery Notes and Shipping labels (free))
<?php //Do not add this line of code
add_filter('wf_pklist_alter_order_date', 'wt_pklist_change_order_date_format', 10, 3);
function wt_pklist_change_order_date_format($order_date, $template_type, $order) {
if ( is_object( $order ) ) {
$order_id = is_object($order) ? $order->get_id() : '';
$order_date_format = 'd/m/y';
$order_date = get_the_date( $order_date_format, $order_id );
}
@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
Created October 24, 2024 05:15
Code to fetch older object using order number - By WebToffee( Sequential Order Number for WooCommerce )
<?php //Do not copy this line of code
$order_number = 123456; // Order number to search for
$args = array(
'limit' =>1,
array(
'key' => '_order_number',
'value' => $order_number,
'compare' => '='
)
);
@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 ){