This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Login { | |
public function hook(){ | |
add_filter( 'determine_current_user', [ $this, 'login_via_token' ], 20 ); | |
add_action( 'rest_api_init', [ $this, 'register_routes' ], 10 ); | |
} | |
public function register_routes(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'rest_product_query', function( $query_args, $request ) { | |
if ( isset( $_GET['search'] ) && ! empty( $_GET['search'] ) && class_exists( '\SWP_Query' ) ) { | |
$query_args['orderby'] = 'post__in'; | |
} | |
return $query_args; | |
}, 99, 2 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'pre_get_posts', function( $query ) { | |
if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) { | |
return | |
} | |
if ( is_admin() || ! isset( $query->query['post_type'] ) || $query->query['post_type'] !== 'product' ) { | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Project\WooCommerce\Gateways; | |
class Estimates extends \WC_Payment_Gateway { | |
const ID = 'estimates-gateway'; | |
const WC_STATUS = 'wc-estimate'; | |
public function __construct() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* If inserting a gif always place the full size image | |
* | |
* @param string $html | |
* @param int $send_id | |
* @param array $attachment | |
* | |
* @return string | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
unload_textdomain( 'woocommerce' ); | |
WC()->countries->states = null; | |
WC()->countries->load_country_states(); | |
$formatted_address = WC()->countries->get_formatted_address( $address ); | |
WC()->load_plugin_textdomain(); | |
WC()->countries->load_country_states(); | |
//$formatted_address was now in English! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'woocommerce_checkout_create_order', function( $order, $data ) { | |
// For my example I only want to do this on payments through cash on delivery gateway | |
// This is not a requirement though, you can do it for any reason you want. | |
if ( $order->get_payment_method() !== 'cod' ) { | |
return; | |
} | |
// I get my fee from the COD gateway settings field we added |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_settings_api_form_fields_cod', function( $form_fields ) { | |
$form_fields[ 'custom_fee' ] = [ | |
'title' => __( 'Fee in $', 'textdomain' ), | |
'type' => 'number', | |
'description' => __( 'Add a fee to orders using Cash on Delivery gateway.', 'textdomain' ), | |
'default' => 0, | |
'min' => 0, | |
'step' => .01, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Heavily borrowed from: http://xplus3.net/2010/08/08/filtering-on-a-non-standard-database-field-with-wordpress/ | |
**/ | |
class CoordinatesTable extends DB { | |
protected $db_option = "coordinates_db"; |
NewerOlder