remove_action From PHP Class - php

I'm attempting to remove an action and add it with a different priority.
Below are all the code snippets that assist in generating a Message:
Include required frontend files
private function frontend_includes() {
require_once( $this->get_plugin_path() . '/includes/wc-memberships-template-functions.php' );
require_once( $this->get_plugin_path() . '/includes/class-wc-memberships-shortcodes.php' );
WC_Memberships_Shortcodes::initialize();
$this->frontend = $this->load_class( '/includes/frontend/class-wc-memberships-frontend.php', 'WC_Memberships_Frontend' );
$this->checkout = $this->load_class( '/includes/frontend/class-wc-memberships-checkout.php', 'WC_Memberships_Checkout' );
$this->restrictions = $this->load_class( '/includes/frontend/class-wc-memberships-restrictions.php', 'WC_Memberships_Restrictions' );
}
Get the product purchasing restricted message
/**
* #param int $post_id Optional. Defaults to current post.
* #return string
*/
public function get_product_purchasing_restricted_message( $post_id = null ) {
if ( ! $post_id ) {
global $post;
$post_id = $post->ID;
}
$products = $this->get_products_that_grant_access( $post_id );
$message = $this->get_restriction_message( 'product_purchasing_restricted', $post_id, $products );
/**
* Filter the product purchasing restricted message
*
* #since 1.0.0
* #param string $message The restriction message
* #param int $product_id ID of the product being restricted
* #param array $products Array of product IDs that grant access to this product
*/
return apply_filters( 'wc_memberships_product_purchasing_restricted_message', $message, $post_id, $products );
}
Restriction class, handles content restriction on frontend
class WC_Memberships_Restrictions {
/** #var array associative array of content conditions for current user **/
private $user_content_access_conditions;
/** #var array of post IDs that content restriction has been applied to **/
private $content_restriction_applied = array();
/** #var string Product content restriction password helper **/
private $product_restriction_password = null;
/** #var bool Product thumbnail removed helper **/
private $product_thumbnail_restricted = false;
public function __construct() {
// Desired action to remove and re-prioritize
add_action( 'woocommerce_single_product_summary', array( $this, 'single_product_purchasing_restricted_message' ), 30 );
}
}
I literally just need to alter the priority to 15 from 30 in the action of the WC_Memberships_Restrictions class. The issue is that there's no clear way to call the removal. Any suggestions?

Well the code you provided shows that the instance of the WC_Memberships_Restrictions class is stored in the main class' restrictions property.
$this->restrictions = $this->load_class( '/includes/frontend/class-wc-memberships-restrictions.php', 'WC_Memberships_Restrictions' );
From there I just had to look up how to access the instance of the main Membership class, from the bottom of the main plugin file you see:
/**
* Returns the One True Instance of Memberships
*
* #since 1.0.0
* #return WC_Memberships
*/
function wc_memberships() {
return WC_Memberships::instance();
}
This means that now to access the instance of the restrictions class we need to access the main class's restriction property. While that sounds clear as mud, basically it means this:
wc_memberships()->restrictions
Knowing this, we can known remove and add actions from that class:
function so_41431558_change_hook_priority(){
if( function_exists( 'wc_memberships' ) ){
remove_action( 'woocommerce_single_product_summary', array( wc_memberships()->restrictions, 'single_product_purchasing_restricted_message' ), 30 );
add_action( 'woocommerce_single_product_summary', array( wc_memberships()->restrictions, 'single_product_purchasing_restricted_message' ), 15 );
}
}
add_action( 'woocommerce_single_product_summary', 'so_41431558_change_hook_priority', 1 );

Related

Populate Products in Custom Endpoint for Woocommerce My Account Page

I am trying to customize the MY ACCOUNT dashboard on WOOCOMMERCE and I was able to create a "custom endpoint" but I need to fill it with the product on the site, getting rid of the "account data info" as well. It shouldn't be showing anything at all with the code I am using.
If anyone can help me out I'd be very appreciative.
dashboard
add_action( 'init', 'register_new_item_endpoint');
/**
* Register New Endpoint.
*
* #return void.
*/
function register_new_item_endpoint() {
add_rewrite_endpoint( 'narcx-products', EP_ROOT | EP_PAGES );
}
add_filter( 'query_vars', 'new_item_query_vars' );
/**
* Add new query var.
*
* #param array $vars vars.
*
* #return array An array of items.
*/
function new_item_query_vars( $vars ) {
$vars[] = 'narcx-products';
return $vars;
}
add_filter( 'woocommerce_account_menu_items', 'add_new_item_tab' );
/**
* Add New tab in my account page.
*
* #param array $items myaccount Items.
*
* #return array Items including New tab.
*/
function add_new_item_tab( $items ) {
$items['narcx-products'] = 'NarcX Products';
return $items;
}
add_action( 'woocommerce_account_new-item_endpoint', 'add_new_item_content' );
add_filter( 'widget_text', 'do_shortcode' );
/**
* Add content to the new tab.
*
* #return string.
*/
function add_new_item_content() {
echo do_shortcode('[products] ');
}
Tried custom endpoint code in my "function.php" file in theme, should be able to remove account data and add products to that endpoint tab in my account page.

How to use underlaying product permalink in WooCommerce bundled items function

I was wondering how to override the default product bundles permalink function. I use the plugin Woocommerce Product bundles for this.
The default function from "class-wc-bundled-item" is this:
/**
* Item permalink.
*
* #since 5.5.0
*
* #return string
*/
public function get_permalink() {
/**
* 'woocommerce_bundled_item_permalink' filter.
*
* #param string $permalink
* #param WC_Bundled_Item $this
*/
return apply_filters( 'woocommerce_bundled_item_permalink', $this->is_visible() && $this->product->is_visible() ? $this->product->get_permalink() : '', $this );
}
I want to override this function in my functions.php file. Unfortunately it returns the permalink of the product bundle and not from the linked (underlaying) product.
This is the code i tried:
add_filter( 'woocommerce_bundled_item_permalink', 'get_bundle_product_permalink' );
function get_bundle_product_permalink() {
return get_permalink();
}
What am i doing wrong?
add_filter( 'woocommerce_product_is_visible', '__return_true' );
Try this code snippet to bypass is_visble check
Something like this?
/* Set the visibility function */
function filter_woocommerce_product_is_visible( $visible, $this_get_id ) {
return apply_filters( 'woocommerce_bundled_item_permalink', '__return_true' );
};
add_filter( 'woocommerce_product_is_visible', 'filter_woocommerce_product_is_visible', 10, 2 );

wooCommerce custom end points

I am a fairly new PHP developer and what I am trying to create is a custom endpoint for the "myaccount" page . I am trying to create a "Add Guest" end point. I am finding it very difficult to find any documentation online. What I have done so far is used this git hub repo
https://gist.github.com/neilgee/13ac00c86c903c4ab30544b2b76c483c/a43701564ab696e1586e2879591c890b67a5f1bf#file-woo-endpoints-order-php
I created these files and put them in the plugins/woocommerce/includes directory. But they seem to take no effect. Have i put them in the correct directory? Am I soppose to call these classes somewhere else ? I have no idea where I going wrong. Can some please educate me on this matter.
<?php
/*
* Add custom endpoint that appears in My Account Page - WooCommerce 2.6
* Ref - https://gist.github.com/claudiosmweb/a79f4e3992ae96cb821d3b357834a005#file-custom-my-account-endpoint-php
*/
class My_Custom_My_Account_Endpoint {
/**
* Custom endpoint name.
*
* #var add_students_details
*/
public static $endpoint = 'add_students_details';
/**
* Plugin actions.
*/
public function __construct() {
// Actions used to insert a new endpoint in the WordPress.
add_action( 'init', array( $this, 'add_endpoints' ) );
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 );
// Change the My Accout page title.
add_filter( 'the_title', array( $this, 'endpoint_title' ) );
// Insering your new tab/page into the My Account page.
add_filter( 'woocommerce_account_menu_items', array( $this, 'new_menu_items' ) );
add_action( 'woocommerce_account_' . self::$endpoint . '_endpoint', array( $this, 'endpoint_content' ) );
}
/**
* Register new endpoint to use inside My Account page.
*
* #see https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/
*/
public function add_endpoints() {
add_rewrite_endpoint( self::$endpoint, EP_ROOT | EP_PAGES );
}
/**
* Add new query var.
*
* #param array $vars
* #return array
*/
public function add_query_vars( $vars ) {
$vars[] = self::$endpoint;
return $vars;
}
/**
* Set endpoint title.
*
* #param string $title
* #return string
*/
public function endpoint_title( $title ) {
global $wp_query;
$is_endpoint = isset( $wp_query->query_vars[ self::$endpoint ] );
if ( $is_endpoint && ! is_admin() && is_main_query() && in_the_loop() && is_account_page() ) {
// New page title.
$title = __( 'My Stuff', 'woocommerce' );
remove_filter( 'the_title', array( $this, 'endpoint_title' ) );
}
return $title;
}
/**
* Insert the new endpoint into the My Account menu.
*
* #param array $items
* #return array
*/
public function new_menu_items( $items ) {
// Remove the logout menu item.
$logout = $items['customer-logout'];
unset( $items['customer-logout'] );
// Insert your custom endpoint.
$items[ self::$endpoint ] = __( 'My Stuff', 'woocommerce' );
// Insert back the logout item.
$items['customer-logout'] = $logout;
return $items;
}
/**
* Endpoint HTML content.
*/
public function endpoint_content() {
wc_get_template( 'myaccount/navigation.php' ); ?>
<div class="woocommerce-MyAccount-content">
<p>Hello World! - custom field can go here</p>
</div>
<?php
}
/**
* Plugin install action.
* Flush rewrite rules to make our custom endpoint available.
*/
public static function install() {
flush_rewrite_rules();
}
}
new My_Custom_My_Account_Endpoint();
// Flush rewrite rules on plugin activation.
register_activation_hook( __FILE__, array( 'My_Custom_My_Account_Endpoint', 'install' ) );
But they seem to take no effect. Have i put them in the correct directory? Am I soppose to call these classes somewhere else ? I have no idea where I going wrong. Can some please educate me on this matter.
First thing, you created a class, but you never loaded that file or initiated the class. The best way to do this would be in your own plugin.
Second, you have to add the add_rewrite_endpoint() to the install function. Otherwise, it doesn't know to register the new endpoint and your rewrite rules are flushed, but end up exactly the same as they were before... which creates some 404 errors.
Third, recent WooCommerce provides a filter for the endpoint title. And the content doesn't need to reproduce the My Account div or navigation.
Tested and working:
<?php
/**
* Plugin Name: WC Custom Endpoint
* Plugin URI: http://stackoverflow.com/questions/38784599/woocommerce-custom-end-points
* Description: A custom endpoint
* Version: 0.1.0
* Author: Kathy Darling
* Author URI: http://kathyisawesome.com
* Text Domain: wc_custom_endpoint
* Domain Path: /languages
* Requires at least: 4.6.0
* Tested up to: 4.6.0
*
* Copyright: © 2016 Kathy Darling.
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
/**
* The Main WC_Custom_Endpoint class
**/
if ( ! class_exists( 'WC_Custom_Endpoint' ) ) :
class WC_Custom_Endpoint {
const VERSION = '0.1.0';
/**
* Custom endpoint name.
*/
public static $endpoint = 'add_students_details';
/**
* #var WC_Custom_Endpoint - the single instance of the class
* #since 0.1.0
*/
protected static $instance = null;
/**
* Plugin Directory
*
* #since 0.1.0
* #var string $dir
*/
public $dir = '';
/**
* Plugin URL
*
* #since 0.1.0
* #var string $url
*/
public $url = '';
/**
* Main WC_Custom_Endpoint Instance
*
* Ensures only one instance of WC_Custom_Endpoint is loaded or can be loaded.
*
* #static
* #see WC_Custom_Endpoint()
* #return WC_Custom_Endpoint - Main instance
* #since 0.1.0
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WC_Custom_Endpoint ) ) {
self::$instance = new WC_Custom_Endpoint();
}
return self::$instance;
}
public function __construct(){
$this->dir = plugin_dir_path(__FILE__);
$this->url = plugin_dir_url(__FILE__);
// Load translation files
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
// Actions used to insert a new endpoint in the WordPress.
add_action( 'init', array( $this, 'add_endpoints' ) );
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 );
// Insering your new tab/page into the My Account page.
add_filter( 'woocommerce_account_menu_items', array( $this, 'new_menu_items' ) );
add_action( 'woocommerce_endpoint_' . self::$endpoint . '_title', array( $this, 'endpoint_title' ) );
add_action( 'woocommerce_account_' . self::$endpoint . '_endpoint', array( $this, 'endpoint_content' ) );
}
/*-----------------------------------------------------------------------------------*/
/* Localization */
/*-----------------------------------------------------------------------------------*/
/**
* Make the plugin translation ready
*
* #return void
* #since 1.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'wc-custom-endpoint' , false , dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/*-----------------------------------------------------------------------------------*/
/* Endpoint */
/*-----------------------------------------------------------------------------------*/
/**
* Register new endpoint to use inside My Account page.
*
* #see https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/
*/
public function add_endpoints() {
add_rewrite_endpoint( self::$endpoint, EP_ROOT | EP_PAGES );
}
/**
* Add new query var.
*
* #param array $vars
* #return array
*/
public function add_query_vars( $vars ) {
$vars[] = self::$endpoint;
return $vars;
}
/*-----------------------------------------------------------------------------------*/
/* Display */
/*-----------------------------------------------------------------------------------*/
/**
* Set endpoint title.
*
* #return string
*/
public function endpoint_title() {
return __( 'My Stuff', 'wc_custom_endpoint' );
}
/**
* Insert the new endpoint into the My Account menu.
*
* #param array $items
* #return array
*/
public function new_menu_items( $items ) {
// Remove the logout menu item.
$logout = $items['customer-logout'];
unset( $items['customer-logout'] );
// Insert your custom endpoint.
$items[ self::$endpoint ] = __( 'My Stuff', 'wc_custom_endpoint' );
// Insert back the logout item.
$items['customer-logout'] = $logout;
return $items;
}
/**
* Endpoint HTML content.
*/
public function endpoint_content() { ?>
<p>Hello World! - custom wc_get_template() can go here</p>
<?php
}
/*-----------------------------------------------------------------------------------*/
/* Activation */
/*-----------------------------------------------------------------------------------*/
/**
* Plugin install action.
* Flush rewrite rules to make our custom endpoint available.
*/
public static function install() {
WC_Custom_Endpoint()->add_endpoints();
flush_rewrite_rules();
}
/**
* Plugin install action.
* Flush rewrite rules to make our custom endpoint available.
*/
public static function uninstall() {
flush_rewrite_rules();
}
} //end class: do not remove or there will be no more guacamole for you
endif; // end class_exists check
/**
* Returns the main instance of WC_Custom_Endpoint to prevent the need to use globals.
*
* #since 1.0
* #return WC_Custom_Endpoint
*/
function WC_Custom_Endpoint() {
return WC_Custom_Endpoint::instance();
}
// Launch the whole plugin
add_action( 'woocommerce_loaded', 'WC_Custom_Endpoint' );
// register activation hook
register_activation_hook( __FILE__, array( 'WC_Custom_Endpoint', 'install' ) );
register_deactivation_hook( __FILE__, array( 'WC_Custom_Endpoint', 'uninstall' ) );

Woocommerce: save_post hook is not being triggered

I have a meta box I'm coding for the product post type that comes with woocommerce. I've run into a problem I can't pass in that the 'save_post' hook does not seem to be working at all with products. It works perfectly for posts, but since I've changed my code to work for products it does nothing. The save_post function I've hooked to does absolutely nothing at the moment. I've added all sorts of code to it and it doesn't matter, the script just doesn't seem to get that far. am I missing something obvious?
Edit: as an aside, I added
?> <script type="text/javascript">
var post_id = '<?php $post_id ?>';
console.log("id is: " + post_id );
</script><?php
But it returns absolutely nothing.
<?php
/*
* Represents the plugin's Meta Box
*
* #since 0.0.1
* #package BBPlugin
* #subpackage BBPlugin
* #author Christopher Dando <captaindando#gmail.com>
*/
/*
* Represents the plugin's Meta Box
*
* Register's the meta box with the WordPress API, sets its properties,
* by including the markup from its associated view
*
* #package BBPlugin
* #subpackage BBPlugin/admin
* #author Christopher Dando <captaindando#gmail.com>
*/
class BBPlugin_Meta_Box{
/*
* Register this class with the wordpress API
*
* #since 0.0.1
*/
public function initialize_hooks(){
//add_action( 'add_meta_boxes_product', array( $this, 'add_meta_box' ) );
add_action( 'add_meta_boxes', array( $this, 'BBadd_meta_box' ) );
// This checks when wordpress is saving or
// updating a post.
add_action( 'save_post', array( $this, 'save_post' ) );
$junk = $post_id;
?> <script type="text/javascript">
var post_id = '<?php global $post; echo $post->ID; ?>';
console.log("id is: " + post_id );
</script><?php
}
// add_meta_boxes is the wordpress function. add_meta_box is our new function
/*
* The function responsible for creating the actual meta box.
*
* #since 0.0.1
*/
public function BBadd_meta_box(){
?> <script>console.log("meta box added");</script><?php
add_meta_box(
'BBPlugin',
"Brave Books",
array( $this, 'display_meta_box' ),
'product',
'normal',
'default'
);
}
// This defines the properties of the meta box.
/*
* Renders the content of the meta box.
*
* #since 0.0.1
*/
public function display_meta_box(){
include_once( 'views/BBPlugin-navigation.php' );
}
/**
* Sanitizes and serializes the information associated with this post.
*
* #since 0.0.1
*
* #param int $post_id The ID of the post that's currently being edited.
*/
// strangely, this calls if the meta box does not render
public function save_post( $post_id ) {
?><script>alert("post saved");</script><?php
/* If we're not working with a 'product' post type or the
user doesn't have permission to save,
then we exit the function.
*/
if ( ! $this->user_can_save( $post_id, 'BBPlugin_nonce', 'BBPlugin_save' ) ) {
return;
}
/*
We need to 'Sanitise' our information before
we can save it to the database. What this means
is that we must strip it of html tags
and extract the text itself.
*/
// If the 'Resources' inputs exist, iterate through them and sanitize them
if ($this->value_exists( 'BBPlugin-resources' ) ) {
// This is all divs with the id of meta-box-resources
$this->update_post_meta(
$post_id,
'BBPlugin-resources',
$this->sanitize_data( 'BBPlugin-resources', true )
);
}
else {
// leaving an input blank on the front end will remove that specific input.
$this->delete_post_meta( $post_id, 'BBPlugin-resources' );
}
}
/**
* Determines whether or not a value exists in the $_POST collection
* identified by the specified key.
*
* #since 0.0.1
*
* #param string $key The key of the value in the $_POST collection.
* #return bool True if the value exists; otherwise, false.
*/
private function value_exists( $key ) {
return ! empty( $_POST[ $key ] );
}
/**
* Deletes the specified meta data associated with the specified post ID
* based on the incoming key.
*
* #since 0.0.1
* #access private
* #param int $post_id The ID of the post containing the meta data
* #param string $meta_key The ID of the meta data value
*/
private function delete_post_meta( $post_id, $meta_key ) {
if ( '' !== get_post_meta( $post_id, $meta_key, true ) ) {
delete_post_meta( $post_id, '$meta_key' );
}
}
private function update_post_meta( $post_id, $meta_key, $meta_value ) {
if ( is_array( $_POST[ $meta_key ] ) ) {
$meta_value = array_filter( $_POST[ $meta_key ] );
}
/*
Update_post_meta also adds to a database if there is nothing there already.
parameters are as follows:
1. The post ID used to associate this information with the post.
2. A meta key that's used to uniquely identify the value.
3. The actual value associated with the meta key.
*/
update_post_meta( $post_id, $meta_key, $meta_value );
}
/**
* Sanitizes the data in the $_POST collection identified by the specified key
* based on whether or not the data is text or is an array.
*
* #since 1.0.0
* #access private
* #param string $key The key used to retrieve the data from the $_POST collection.
* #param bool $is_array Optional. True if the incoming data is an array.
* #return array|string The sanitized data.
*/
private function sanitize_data( $key, $is_array = false ) {
$sanitized_data = null;
if ( $is_array ) {
$resources = $_POST[ $key ];
$sanitized_data = array();
foreach ( $resources as $resource ) {
$resource = esc_url( strip_tags( $resource ) );
if ( ! empty( $resource ) ) {
$sanitized_data[] = $resource;
}
}
}
else {
$sanitized_data = '';
$sanitized_data = trim( $_POST[ $key ] );
$sanitized_data = esc_textarea( strip_tags( $sanitized_data ) );
}
return $sanitized_data;
}
/**
* Verifies that the post type that's being saved is actually a post (versus a page or another
* custom post type.
*
*
* #since 0.0.1
* #access private
* #return bool Return if the current post type is a post; false, otherwise.
*/
private function is_valid_post_type() {
return ! empty( $_POST['post_type'] ) && 'post' == $_POST['post_type'];
}
/**
* Determines whether or not the current user has the ability to save meta data associated with this post.
*
* #since 0.0.1
* #access private
* #param int $post_id The ID of the post being save
* #param string $nonce_action The name of the action associated with the nonce.
* #param string $nonce_id The ID of the nonce field.
* #return bool Whether or not the user has the ability to save this post.
*/
private function user_can_save( $post_id, $nonce_action, $nonce_id ) {
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ $nonce_action ] ) && wp_verify_nonce( $_POST[ $nonce_action ], $nonce_id ) );
// Return true if the user is able to save; otherwise, false.
return ! ( $is_autosave || $is_revision ) && $this->is_valid_post_type() && $is_valid_nonce;
}
}
?>
In Wordpress, save_post isn't a destination in itself; it is an action carried out effectively 'between' pages: you hit Update, and Wordpress will carry out a series of actions behind the scenes before returning you to the appropriate page (invariably the post you were just editing, with a notification about the status of that save).
As such, you will never see the results of an echo, print_r, or JS alert or console.log, because save_post isn't a user-facing action.
If you want to see if your save_post action is being carried out in this way, I would recommend throwing in a die(), like so:
public function save_post($post_id) {
?><script>alert("post saved");</script><?php
die();
}
If the save_post action is being fired correctly, then you should see the JS alert over a blank page. If you want to see if your function is carrying out any actual Wordpress-style functionality, I'd recommend a simple update_post_meta to confirm:
public function save_post($post_id) {
// Insert some actual logic to ensure you're not doing this on every post all the time
update_post_meta($post_id, 'i_am_saved', 'totes saved to post #' . $post_id);
}
You can then check the database (or click to view the custom fields within that post) to see if your custom metadata has been added.
I would also recommend attaching your save_post action specifically to the product post type that's used by WooCommerce:
add_action('save_post_product', array($this, 'save_post'));
That will save some redundancy checking later.

Woocommerce shipping method

I want developing a shipping plugin for Woocommerce
I want to send parameters to a third party api
Tell me how to do is the right
Name Phone mail is required.
It's my code
English is not good, please forgive me.
How do I fix this?
Thank you.
<?php
/*
Plugin Name: Ship
Plugin URI: http://woothemes.com/woocommerce
Description: Ship-Jay Hsu
Version: 1.0.0
Author: JayHsu
Author URI: http://
*/
/**
* Check if WooCommerce is active
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
function EG($order){
global $woocommerce; global $post;
$billing_first_name = $woocommerce->session->get('billing_first_name');
$billing_last_name = $woocommerce->session->get('billing_last_name');
$cardurl = 'http://myshoptest.net.php?'.
'&Pay_zg=41' .
'&Rvg2c=1' .
'&Od_sob=' .$order_name.
'&Pur_name=' .$billing_first_name.$billing_last_name.
'&Mobile_number=' .$order->billing_phone.
'&Email=' .$order->billing_email.
'&Roturl_status=' . 'woook'.
'&Roturl=' . $Vk.
'&Remark=woocommerce';
header("Location: $cardurl");
exit();
}
function SFNM_init() {
if ( ! class_exists( 'WC_SFNM' ) ) {
class WC_SFNM extends WC_Shipping_Method {
/**
* Constructor for your shipping class
*
* #access public
* #return void
*/
public function __construct() {
$this->id = 'SFNM'; // Id for your shipping method. Should be uunique.
$this->method_title = __( 'Ship' ); // Title shown in admin
$this->method_description = __( 'Ship' ); // Description shown in admin
$this->enabled = "yes"; // This can be added as an setting but for this example its forced enabled
$this->title = "Ship"; // This can be added as an setting but for this example its forced.
$this->init_form_fields();
$this->init();
}
/**
* Init your settings
*
* #access public
* #return void
*/
function init() {
// Load the settings API
$this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings
$this->init_settings(); // This is part of the settings API. Loads settings you previously init.
// Save settings in admin if you have any defined
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
}
/**
* calculate_shipping function.
*
* #access public
* #param mixed $package
* #return void
*/
public function calculate_shipping( $package ) {
$rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => '60',
'calc_tax' => 'per_item'
);
// Register the rate
$this->add_rate( $rate );
}
}
}
}
add_action( 'woocommerce_shipping_init', 'SFNM_init' );
add_action( 'woocommerce_thankyou','EG');
function add_SFNM_method( $methods ) {
$methods[] = 'WC_SFNM';
return $methods;
}
add_filter( 'woocommerce_shipping_methods', 'add_SFNM_method' );
}
?>

Categories