Skip to content

Instantly share code, notes, and snippets.

View iyut's full-sized avatar

Luthfi Bintoro iyut

View GitHub Profile
@iyut
iyut / functions.php
Created September 22, 2023 03:16
Deactivate new Astra Header/Footer Builder
function theme_is_header_footer_builder_active( $is_header_footer_builder_active ) {
return false;
}
add_filter( 'astra_is_header_footer_builder_active', 'theme_is_header_footer_builder_active', 10, 1 );
@iyut
iyut / filter_product_category.php
Created August 10, 2021 14:30
Manipulate product category query
function display_user_subscription_product( $product_ids ) {
// Only on Product Category archives pages
if( is_admin() || ! is_product_category( 'membership' ) || ! is_user_logged_in() ) return $product_ids;
$subscription_product_id = get_user_meta( get_current_user_id(), 'current_user_subscription_product_id', true );
if ( is_numeric( $subscription_product_id ) && ! empty( $subscription_product_id ) ) {
$product_ids[] = $subscription_product_id;
}
return $product_ids;
@iyut
iyut / create_wc_product.php
Created August 10, 2021 14:29
Create Woo Product
// Custom function for product creation (For Woocommerce 3+ only)
function create_product( $args ){
if( ! function_exists('wc_get_product_object_type') && ! function_exists('wc_prepare_product_attributes') )
return false;
// Get an empty instance of the product object (defining it's type)
$product = wc_get_product_object_type( $args['type'] );
if( ! $product )
return false;
@iyut
iyut / add_barcode_url_in_api_response.php
Last active July 16, 2021 08:12
Manipulate WC Order REST API Response
/**
* Add the barcode URL in REST API responses.
* @since 1.3.24
* @param object $response WP_REST_Response
* @param object $object Order Object
* @param object $request The request made to WC-API
* @return object $response
*/
function add_barcode_url_in_api_response ( $response, $object, $request ) {
if ( is_a( $response, 'WP_REST_Response' ) && is_a( $object, 'WC_Order' ) ) {
@iyut
iyut / functions.php
Created June 24, 2021 05:05
wp_remote_post using x-www-form-urlencoded
function request_token() {
$encoded_auth = base64_encode( $this->client_id . ":" . $this->client_secret );
$args = array(
'method' => 'POST',
'httpversion' => '1.1',
'headers' => array(
'Authorization' => 'Basic '. $encoded_auth,
'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8',
),
@iyut
iyut / functions.php
Created April 28, 2021 09:10
Remove postcode field on WooCommerce shipping calculator
add_filter( 'woocommerce_shipping_calculator_enable_postcode', '__return_false' );
@iyut
iyut / functions.php
Created April 27, 2021 16:23
Get All WP Cron in WordPress
add_action( 'wp_footer', function(){
$cron_jobs = get_option( 'cron' );
var_dump($cron_jobs);
});
@iyut
iyut / functions.php
Created March 15, 2021 13:14
Hook after product is created or updated
add_action( 'save_post', 'product_created_or_updated', 10, 3);
function product_created_or_updated($post_id, $post, $update){
if ($post->post_status != 'publish' || $post->post_type != 'product') {
return;
}
if ( !$product = wc_get_product( $post_id ) ) {
return;
}
@iyut
iyut / functions.php
Last active March 15, 2021 13:12
Woocommerce Hook After Order is created
add_action( 'woocommerce_new_order', 'order_is_created', 10, 1 );
function order_is_created( $order_id ){
$order = wc_get_order( $order_id );
if( !$order ){
return;
}
}
@iyut
iyut / split_by_quantity.php
Last active March 5, 2021 12:42
Splitting the cart by quantity
function custom_split_shipping_packages_shipping_class( $packages ) {
// Reset all packages
$packages = array();
$split_package_qty = array();
foreach ( WC()->cart->get_cart() as $item_key => $item ) {
for( $i = 0; $i < $item['quantity']; $i++ ){