Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small updates #14

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 44 additions & 43 deletions dokan-invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,26 @@ public function __construct() {

$this->depends_on['woocommerce_pdf_invoices'] = array(
'name' => 'WooCommerce_PDF_Invoices',
'notice' => sprintf( __( '<b>Dokan PDF Invoice </b> requires %sWooCommerce PDF Invoices & packing slips plugin%s to be installed & activated!' , 'dokan-invoice' ), '<a target="_blank" href="https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/">', '</a>' ),
'notice' => sprintf( __( '<b>Dokan PDF Invoice </b> requires %sPDF Invoices & Packing Slips for WooCommerce plugin%s to be installed & activated!' , 'dokan-invoice' ), '<a target="_blank" href="https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/">', '</a>' ),
);

add_action( 'before_woocommerce_init', [ $this, 'add_hpos_support' ] );
add_action( 'before_woocommerce_init', [ $this, 'add_hpos_support' ] );
add_action( 'init', array( $this,'is_dependency_available') );
add_action( 'plugins_loaded', array( $this, 'init_hooks' ) );
}

/**
* Add High Performance Order Storage Support.
*
* @since 1.2.2
*
* @return void
*/
public function add_hpos_support() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
/**
* Add High Performance Order Storage Support.
*
* @since 1.2.2
*
* @return void
*/
public function add_hpos_support() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}

/**
* check if dependencies installed or not and add error notice
Expand Down Expand Up @@ -167,8 +167,8 @@ public function init_hooks() {

add_action( 'init', array( $this, 'localization_setup' ) );
add_filter( 'dokan_my_account_my_sub_orders_actions', array( $this, 'dokan_invoice_listing_actions_my_account' ), 50, 2 );
add_filter( 'wpo_wcpdf_shop_name', array( $this,'wpo_wcpdf_add_dokan_shop_name'), 10, 2 );
add_filter( 'wpo_wcpdf_shop_address', array( $this,'wpo_wcpdf_add_dokan_shop_details'), 10, 2 );
add_filter( 'wpo_wcpdf_shop_name_settings_text', array( $this,'wpo_wcpdf_add_dokan_shop_name'), 10, 2 );
add_filter( 'wpo_wcpdf_shop_address_settings_text', array( $this,'wpo_wcpdf_add_dokan_shop_details'), 10, 2 );
add_filter( 'wpo_wcpdf_check_privs', array( $this,'wpo_wcpdf_dokan_privs'), 50, 2 );
}

Expand Down Expand Up @@ -224,32 +224,33 @@ public function dokan_invoice_listing_actions_my_account( $actions, $order ) {
public function wpo_wcpdf_add_dokan_shop_name( $shop_name, $document = null ) {
extract( $this->get_order_id_parent_id( $document ) );

// If parent order keep Original Store name else set seller store name
if ( $parent_id == 0 ) {
$dokan_shop_name = $shop_name;
$store_name = '';

// if parent order keep Original Store name else set seller store name
if ( 0 === $parent_id ) {
if ( function_exists( 'dokan_get_seller_ids_by' ) ) {
$seller_list = dokan_get_seller_ids_by( $order_id );
} else {
$seller_list = array_unique( array_keys( dokan_get_sellers_by( $order_id ) ) );
}

if ( count( $seller_list ) > 1 ) {
return $shop_name;
} else {
$vendor_id = $seller_list[0];
$vendor = dokan()->vendor->get( $vendor_id );
$store_name = $vendor->get_shop_name();
$store_name = ! empty( $store_name ) ? $store_name : __( 'store_info', 'dokan-invoice' );

return $shop_name . "<br /><br />" . __( 'Vendor:', 'dokan-invoice' ) . $store_name;
if ( 1 === count( $seller_list ) ) {
$vendor_id = $seller_list[0];
$vendor = dokan()->vendor->get( $vendor_id );
$store_name = $vendor->get_shop_name();
$store_name = ! empty( $store_name ) ? $store_name : __( 'store_info', 'dokan-invoice' );
$dokan_shop_name .= "<br /><br />" . __( 'Vendor:', 'dokan-invoice' ) . $store_name;
}
} else {
$vendor_id = dokan_get_seller_id_by_order( $order_id );
$vendor = dokan()->vendor->get( $vendor_id );
$store_name = $vendor->get_shop_name();
$store_name = ! empty( $store_name ) ? $store_name : __( 'store_info', 'dokan-invoice' );

return $shop_name . "<br /><br />" . __( 'Vendor:', 'dokan-invoice' ) . $store_name;
$vendor_id = dokan_get_seller_id_by_order( $order_id );
$vendor = dokan()->vendor->get( $vendor_id );
$store_name = $vendor->get_shop_name();
$store_name = ! empty( $store_name ) ? $store_name : __( 'store_info', 'dokan-invoice' );
$dokan_shop_name .= "<br /><br />" . __( 'Vendor:', 'dokan-invoice' ) . $store_name;
}

return apply_filters( 'dokan_invoice_shop_name', $dokan_shop_name, $shop_name, $store_name, $document );
}

/**
Expand Down Expand Up @@ -285,18 +286,18 @@ public function wpo_wcpdf_add_dokan_shop_details( $shop_address, $document = nul
}
} else {
$vendor_id = $seller_list[0];
/**
* @since 1.2.1 added filter hook dokan_invoice_single_seller_address
*/
/**
* @since 1.2.1 added filter hook dokan_invoice_single_seller_address
*/
$shop_address = "<br>" . apply_filters( 'dokan_invoice_single_seller_address', dokan_get_seller_address( $vendor_id ), $vendor_id, $order_id );
}

return $shop_address;
} else {
$vendor_id = dokan_get_seller_id_by_order( $order_id );
/**
* @since 1.2.1 added filter hook dokan_invoice_single_seller_address
*/
/**
* @since 1.2.1 added filter hook dokan_invoice_single_seller_address
*/
$shop_address = "<br>" . apply_filters( 'dokan_invoice_single_seller_address', dokan_get_seller_address( $vendor_id ), $vendor_id, $order_id );

return $shop_address;
Expand Down Expand Up @@ -362,9 +363,9 @@ public function get_order_id_parent_id( $document = null ) {
if (empty($document) || empty($document->order)) {
// PDF Invoice 1.X backwards compatibility
global $wpo_wcpdf;
/**
* @var $order WC_Order
*/
/**
* @var $order WC_Order
*/
$order = $wpo_wcpdf->export->order;
$order_id = $order->get_id();
$parent_id = $order->get_parent_id();
Expand All @@ -374,7 +375,7 @@ public function get_order_id_parent_id( $document = null ) {
} else {
$order_id = $document->order_id;
}
$order = wc_get_order( $order_id );
$order = wc_get_order( $order_id );
$parent_id = $order->get_parent_id();
}

Expand Down