Skip to content

Instantly share code, notes, and snippets.

View webdados's full-sized avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / vcex_social_links_profiles.php
Last active January 7, 2020 13:33
Add new options to the Visual Composer Social Links module
@webdados
webdados / redirect_if_not_logged_in.php
Created January 6, 2020 13:48
Poor guy's Private WordPress Website - Redirect a user to the login form if he's not logged in
<?php
add_action( 'template_redirect', 'redirect_if_not_logged_in' );
function redirect_if_not_logged_in() {
if ( ! is_user_logged_in() ) wp_redirect( wp_login_url( $_SERVER['REQUEST_URI'] ) );
}
@webdados
webdados / shop_as_client_pro_customer_data.php
Last active April 2, 2024 10:55
How to add custom fields to the Shop as Client PRO add-on ajax call - Classic Checkout
<?php
/* Add this to you (child-)theme functions.php file, on a (mu-)plugin or with a plugin like Code Snippets https://wordpress.org/plugins/code-snippets/ */
/* This only works with the classic checkout */
add_filter( 'shop_as_client_pro_customer_data', 'my_shop_as_client_pro_customer_data', 10, 3 );
function my_shop_as_client_pro_customer_data( $data, $customer = null, $order = null ) {
//Are we getting a "customer" object?
if ( $customer ) {
//Custom checkout field with id "billing_xpto"
@webdados
webdados / woocommerce_get_availability.php
Last active June 28, 2024 11:53
Change "available on backorder" WooCommerce text
<?php
add_filter( 'woocommerce_get_availability', 'my_woocommerce_get_availability' );
function my_woocommerce_get_availability( $availability ) {
if ( $availability['class'] === 'available-on-backorder' ) {
$availability['availability'] = 'Your text here';
// or, if you have localized strings
// $availability['availability'] = __( 'Your text here', 'your-textdomain' );
}
@webdados
webdados / woocommerce_display_product_attributes.php
Created November 11, 2019 09:45
Using woocommerce_display_product_attributes
<?php
add_filter( 'woocommerce_display_product_attributes', 'extra_product_information', 10, 2 );
function extra_product_information( $product_attributes, $product ) {
$the_value = $product->get_meta( '_any_custom_field' );
if ( trim( $the_value ) != '' ) {
$product_attributes['any_custom_field'] = array(
'label' => 'Your label',
'value' => $the_value
);
<?php
/* Add each filter to your (child-)theme functions.php file if you want to change any configuration */
//Separator between options (default: new line)
add_filter( 'invoicexpress_woocommerce_eo_separator', function( $string ) {
return PHP_EOL;
} );
//Start before each option (default: '- ')
add_filter( 'invoicexpress_woocommerce_eo_start', function( $string ) {
@webdados
webdados / portugal_ctt_tracking_email_info.php
Created September 11, 2019 15:35
portugal_ctt_tracking_email_info
<?php
add_filter( 'portugal_ctt_tracking_email_info', 'my_portugal_ctt_tracking_email_info', 10, 4 );
function my_portugal_ctt_tracking_email_info( $html, $order_object, $sent_to_admin, $plain_text ) {
//Do whatever you want with the HTML
//You can get the tracking code with $order_object->get_meta( '_ctt_tracking_code' )
return $html;
}
@webdados
webdados / shop_as_client_allow_checkout.php
Last active July 17, 2023 09:36
Shop as Client - Allow other user roles to use the functionality (Shop managers and Administrators already have the ability to do so)
<?php
add_filter( 'shop_as_client_allow_checkout', function() {
$user = wp_get_current_user();
return in_array( 'whatver_role', (array) $user->roles );
} );
@webdados
webdados / woocommerce_checkout_fields.php
Created July 8, 2019 09:14
Manipulate VAT field position on Invoicing with InoiceXpress for WooCommerce
<?php
add_filter( 'woocommerce_checkout_fields', 'my_woocommerce_checkout_fields', 60 );
function my_woocommerce_checkout_fields( $fields ) {
if ( isset( $fields['billing']['billing_VAT_code'] ) ) {
$fields['billing']['billing_VAT_code']['class'] = array( 'form-row-first' ); //Or form-row-last
$fields['billing']['billing_VAT_code']['clear'] = true; //Or false if we use form-row-last
$fields['billing']['billing_VAT_code']['priority'] = 120; //120 is the default position, change this to move it up or down on the form
}
return $fields;
}
@webdados
webdados / woocommerce_portugal_address_format_include_state.php
Created June 3, 2019 12:40
Add "distrito" to the Portuguese address format while using the "Portugal States (Distritos) for WooCommerce" plugin
<?php
//Add to your (child-)theme functions.php file
add_filter( 'woocommerce_portugal_address_format_include_state', '__return_true' );