Skip to content

Instantly share code, notes, and snippets.

View bobwol's full-sized avatar
💭
coding as usual

bobwol

💭
coding as usual
View GitHub Profile
@bobwol
bobwol / wc-rename-tabs.php
Created October 3, 2020 19:10 — forked from woogists/wc-rename-tabs.php
[Frontend Snippets][Editing product data tabs] Renaming product data tabs
/**
* Rename product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
$tabs['description']['title'] = __( 'More Information' ); // Rename the description tab
$tabs['reviews']['title'] = __( 'Ratings' ); // Rename the reviews tab
$tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab
@bobwol
bobwol / wc-reorder-tabs.php
Created October 3, 2020 19:10 — forked from woogists/wc-reorder-tabs.php
[Frontend Snippets][Editing product data tabs] Reordering product data tabs
/**
* Reorder product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
$tabs['reviews']['priority'] = 5; // Reviews first
$tabs['description']['priority'] = 10; // Description second
$tabs['additional_information']['priority'] = 15; // Additional information third
@bobwol
bobwol / wc-custom-tab.php
Created October 3, 2020 19:10 — forked from woogists/wc-custom-tab.php
[Frontend Snippets][Editing product data tabs] Customize a tab
/**
* Customize product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
function woo_custom_description_tab( $tabs ) {
$tabs['description']['callback'] = 'woo_custom_description_tab_content'; // Custom description callback
return $tabs;
}
@bobwol
bobwol / wc-add-additional-information.php
Created October 3, 2020 19:09 — forked from woogists/wc-add-additional-information.php
[Frontend Snippets][Editing product data tabs] Add additional information
/**
* Check if product has attributes, dimensions or weight to override the call_user_func() expects parameter 1 to be a valid callback error when changing the additional tab
*/
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
global $product;
if( $product->has_attributes() || $product->has_dimensions() || $product->has_weight() ) { // Check if product has attributes, dimensions or weight
@bobwol
bobwol / wc-add-custom-tab.php
Created October 3, 2020 19:09 — forked from woogists/wc-add-custom-tab.php
[Frontend Snippets][Editing product data tabs] Add a custom tab
/**
* Add a custom product data tab
*/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
@bobwol
bobwol / wc-integration-demo.php
Created October 3, 2020 19:09 — forked from woogists/wc-integration-demo.php
[Extending][Implementing the WC Integration Class] WooCommerce integration demo
<?php
/**
* Plugin Name: WooCommerce Integration Demo
* Plugin URI: https://gist.github.com/BFTrick/091d55feaaef0c5341d8
* Description: A plugin demonstrating how to add a new WooCommerce integration.
* Author: Patrick Rauland
* Author URI: http://speakinginbytes.com/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
@bobwol
bobwol / wc-automatically-complete-orders.php
Created October 3, 2020 19:09
[Frontend Snippets] Automatically complete all orders
/**
* Auto Complete all WooCommerce orders.
*/
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
@bobwol
bobwol / wc-create-section-beneath-products.php
Created October 3, 2020 19:09 — forked from woogists/wc-create-section-beneath-products.php
[Extending][Adding a Section to a Settings Tab] How to create a section beneath the products tab
/**
* Create the section beneath the products tab
**/
add_filter( 'woocommerce_get_sections_products', 'wcslider_add_section' );
function wcslider_add_section( $sections ) {
$sections['wcslider'] = __( 'WC Slider', 'text-domain' );
return $sections;
}
@bobwol
bobwol / wc-add-settings-section.php
Created October 3, 2020 19:09 — forked from woogists/wc-add-settings-section.php
[Extending][Adding a Section to a Settings Tab] How to add settings to a section
/**
* Add settings to the specific section we created before
*/
add_filter( 'woocommerce_get_settings_products', 'wcslider_all_settings', 10, 2 );
function wcslider_all_settings( $settings, $current_section ) {
/**
* Check the current section is what we want
**/
if ( $current_section == 'wcslider' ) {
$settings_slider = array();
@bobwol
bobwol / wc-add-message-login-form.php
Created October 3, 2020 19:09 — forked from woogists/wc-add-message-login-form.php
[Frontend Snippets] Add a message above the login / register form
/**
* Add a message above the login / register form on my-account page
*/
add_action( 'woocommerce_before_customer_login_form', 'jk_login_message' );
function jk_login_message() {
if ( get_option( 'woocommerce_enable_myaccount_registration' ) == 'yes' ) {
?>
<div class="woocommerce-info">
<p><?php _e( 'Returning customers login. New users register for next time so you can:' ); ?></p>
<ul>